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

Side by Side Diff: Source/WebKit/chromium/src/WebViewImpl.cpp

Issue 8714006: Add autoresize capability for Chromium. (Closed) Base URL: http://git.chromium.org/external/WebKit_trimmed.git@master
Patch Set: Created 9 years 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 | « Source/WebKit/chromium/src/WebViewImpl.h ('k') | Tools/DumpRenderTree/chromium/WebViewHost.h » ('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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "DocumentLoader.h" 49 #include "DocumentLoader.h"
50 #include "DragController.h" 50 #include "DragController.h"
51 #include "DragData.h" 51 #include "DragData.h"
52 #include "DragScrollTimer.h" 52 #include "DragScrollTimer.h"
53 #include "DragSession.h" 53 #include "DragSession.h"
54 #include "Editor.h" 54 #include "Editor.h"
55 #include "EventHandler.h" 55 #include "EventHandler.h"
56 #include "Extensions3D.h" 56 #include "Extensions3D.h"
57 #include "FocusController.h" 57 #include "FocusController.h"
58 #include "FontDescription.h" 58 #include "FontDescription.h"
59 #include "Frame.h"
59 #include "FrameLoader.h" 60 #include "FrameLoader.h"
60 #include "FrameSelection.h" 61 #include "FrameSelection.h"
61 #include "FrameTree.h" 62 #include "FrameTree.h"
62 #include "FrameView.h" 63 #include "FrameView.h"
63 #include "GeolocationClientProxy.h" 64 #include "GeolocationClientProxy.h"
64 #include "GraphicsContext.h" 65 #include "GraphicsContext.h"
65 #include "GraphicsContext3D.h" 66 #include "GraphicsContext3D.h"
66 #include "GraphicsContext3DPrivate.h" 67 #include "GraphicsContext3DPrivate.h"
67 #include "HTMLInputElement.h" 68 #include "HTMLInputElement.h"
68 #include "HTMLMediaElement.h" 69 #include "HTMLMediaElement.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 #include "TypingCommand.h" 108 #include "TypingCommand.h"
108 #include "UserGestureIndicator.h" 109 #include "UserGestureIndicator.h"
109 #include "Vector.h" 110 #include "Vector.h"
110 #include "WebAccessibilityObject.h" 111 #include "WebAccessibilityObject.h"
111 #include "WebAutofillClient.h" 112 #include "WebAutofillClient.h"
112 #include "WebCompositorImpl.h" 113 #include "WebCompositorImpl.h"
113 #include "WebDevToolsAgentImpl.h" 114 #include "WebDevToolsAgentImpl.h"
114 #include "WebDevToolsAgentPrivate.h" 115 #include "WebDevToolsAgentPrivate.h"
115 #include "WebDragData.h" 116 #include "WebDragData.h"
116 #include "WebFrameImpl.h" 117 #include "WebFrameImpl.h"
118 #include "WebFrameClient.h"
117 #include "WebGraphicsContext3D.h" 119 #include "WebGraphicsContext3D.h"
118 #include "WebImage.h" 120 #include "WebImage.h"
119 #include "WebInputElement.h" 121 #include "WebInputElement.h"
120 #include "WebInputEvent.h" 122 #include "WebInputEvent.h"
121 #include "WebInputEventConversion.h" 123 #include "WebInputEventConversion.h"
122 #include "WebKit.h" 124 #include "WebKit.h"
123 #include "WebKitPlatformSupport.h" 125 #include "WebKitPlatformSupport.h"
124 #include "WebMediaPlayerAction.h" 126 #include "WebMediaPlayerAction.h"
125 #include "WebNode.h" 127 #include "WebNode.h"
126 #include "WebPlugin.h" 128 #include "WebPlugin.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 WebViewImpl::WebViewImpl(WebViewClient* client) 329 WebViewImpl::WebViewImpl(WebViewClient* client)
328 : m_client(client) 330 : m_client(client)
329 , m_autofillClient(0) 331 , m_autofillClient(0)
330 , m_permissionClient(0) 332 , m_permissionClient(0)
331 , m_spellCheckClient(0) 333 , m_spellCheckClient(0)
332 , m_chromeClientImpl(this) 334 , m_chromeClientImpl(this)
333 , m_contextMenuClientImpl(this) 335 , m_contextMenuClientImpl(this)
334 , m_dragClientImpl(this) 336 , m_dragClientImpl(this)
335 , m_editorClientImpl(this) 337 , m_editorClientImpl(this)
336 , m_inspectorClientImpl(this) 338 , m_inspectorClientImpl(this)
339 , m_autoSize(false)
340 , m_inLayoutBeforeScrollbarUpdate(false)
337 , m_observedNewNavigation(false) 341 , m_observedNewNavigation(false)
338 #ifndef NDEBUG 342 #ifndef NDEBUG
339 , m_newNavigationLoader(0) 343 , m_newNavigationLoader(0)
340 #endif 344 #endif
341 , m_zoomLevel(0) 345 , m_zoomLevel(0)
342 , m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier)) 346 , m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier))
343 , m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier)) 347 , m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier))
344 , m_minimumPageScaleFactor(minPageScaleFactor) 348 , m_minimumPageScaleFactor(minPageScaleFactor)
345 , m_maximumPageScaleFactor(maxPageScaleFactor) 349 , m_maximumPageScaleFactor(maxPageScaleFactor)
346 , m_contextMenuAllowed(false) 350 , m_contextMenuAllowed(false)
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 pluginContainer->willStartLiveResize(); 1034 pluginContainer->willStartLiveResize();
1031 } 1035 }
1032 1036
1033 void WebViewImpl::resize(const WebSize& newSize) 1037 void WebViewImpl::resize(const WebSize& newSize)
1034 { 1038 {
1035 if (m_size == newSize) 1039 if (m_size == newSize)
1036 return; 1040 return;
1037 m_size = newSize; 1041 m_size = newSize;
1038 1042
1039 if (mainFrameImpl()->frameView()) { 1043 if (mainFrameImpl()->frameView()) {
1040 mainFrameImpl()->frameView()->resize(m_size.width, m_size.height); 1044 // Maintain the current frame size when doing autosize but still send
1045 // a resize event for any auto-resizes that happened.
1046 if (!m_autoSize)
1047 mainFrameImpl()->frameView()->resize(m_size.width, m_size.height);
1041 mainFrameImpl()->frame()->eventHandler()->sendResizeEvent(); 1048 mainFrameImpl()->frame()->eventHandler()->sendResizeEvent();
1042 } 1049 }
1043 1050
1044 if (m_client) { 1051 if (m_client) {
1045 if (isAcceleratedCompositingActive()) { 1052 if (isAcceleratedCompositingActive()) {
1046 #if USE(ACCELERATED_COMPOSITING) 1053 #if USE(ACCELERATED_COMPOSITING)
1047 updateLayerTreeViewport(); 1054 updateLayerTreeViewport();
1048 #endif 1055 #endif
1049 } else { 1056 } else {
1050 WebRect damagedRect(0, 0, m_size.width, m_size.height); 1057 WebRect damagedRect(0, 0, m_size.width, m_size.height);
1051 m_client->didInvalidateRect(damagedRect); 1058 m_client->didInvalidateRect(damagedRect);
1052 } 1059 }
1053 } 1060 }
1054 } 1061 }
1055 1062
1063 void WebViewImpl::layoutBeforeScrollbarUpdate()
darin (slow to review) 2011/11/28 16:50:40 It feels like this should be a function on FrameVi
levin 2011/11/28 18:34:01 I was mildly considering that. I'm not sure it we
levin 2011/11/28 18:39:06 I guess as long as it is ifdef'ed we could add all
1064 {
1065 if (!m_autoSize)
1066 return;
1067
1068 if (!mainFrameImpl()->client())
1069 return;
1070
1071 if (m_inLayoutBeforeScrollbarUpdate)
1072 return;
1073
1074 m_inLayoutBeforeScrollbarUpdate = true;
1075
1076 double zoomFactor = WebView::zoomLevelToZoomFactor(zoomLevel());
1077
1078 WebCore::Frame* frame = mainFrameImpl()->frame();
1079 WebCore::FrameView* frameView = frame->view();
1080 WebCore::Document* document = frame->document();
1081 for (int i = 0; i < 2; i++) {
1082 // Update various sizes including contentsSize.
1083 document->updateLayoutIgnorePendingStylesheets();
1084 WebSize size = frameView->frameRect().size();
1085 // During the first iteration, we use the preferred width but after that we use the width
1086 // that was determined during the first iteration (which may be smaller than the preferred width
1087 // in order to fit within the framerect).
1088 int width = (i == 0) ? mainFrameImpl()->contentsPreferredWidth() : frame View->contentsSize().width();
1089 // Adjust the size because it is reported unzoomed.
1090 int height = static_cast<int>(zoomFactor * mainFrameImpl()->documentElem entScrollHeight());
1091
1092 WebSize newSize(width, height);
1093
1094 // Ensure the size is at least the min bounds.
1095 newSize.width = std::max(newSize.width, m_minAutoSize.width);
1096 newSize.height = std::max(newSize.height, m_minAutoSize.height);
1097
1098 // Increase the dimensions due to any scrollbars that are displayed.
1099 if (newSize.width > m_maxAutoSize.width) {
1100 RefPtr<Scrollbar> horizontalScrollbar = frameView->createScrollbar(W ebCore::HorizontalScrollbar);
1101 if (!horizontalScrollbar->isOverlayScrollbar())
1102 newSize.height += horizontalScrollbar->height();
1103 } else if (newSize.height > m_maxAutoSize.height) {
1104 RefPtr<Scrollbar> verticalScrollbar = frameView->createScrollbar(Web Core::VerticalScrollbar);
1105 if (!verticalScrollbar->isOverlayScrollbar())
1106 newSize.width += verticalScrollbar->width();
1107 }
1108
1109 // Bound the dimensions by the max bounds.
1110 ScrollbarMode horizonalScrollbarMode = ScrollbarAlwaysOff;
1111 if (newSize.width > m_maxAutoSize.width) {
1112 newSize.width = m_maxAutoSize.width;
1113 horizonalScrollbarMode = ScrollbarAlwaysOn;
1114 }
1115 ScrollbarMode verticalScrollbarMode = ScrollbarAlwaysOff;
1116 if (newSize.height > m_maxAutoSize.height) {
1117 newSize.height = m_maxAutoSize.height;
1118 verticalScrollbarMode = ScrollbarAlwaysOn;
1119 }
1120
1121 if (newSize == size)
1122 continue;
1123
1124 // Avoid doing resizing to a smaller size while the frame is loading to avoid changing between too many sizes.
1125 if (!frame->loader()->isComplete() && (newSize.width < size.width || new Size.width < size.width))
1126 break;
1127 frameView->resize(newSize.width, newSize.height);
1128 // Force the scrollbar state to avoid the scrollbar code adding them and causing them to be needed. For example,
1129 // a vertical scrollbar may cause text to wrap and thus increase the hei ght (which is the only reason the scollbar is needed).
1130 frameView->setVerticalScrollbarLock(false);
1131 frameView->setHorizontalScrollbarLock(false);
1132 frameView->setScrollbarModes(horizonalScrollbarMode, verticalScrollbarMo de, true, true);
1133 }
1134
1135 m_inLayoutBeforeScrollbarUpdate = false;
1136 }
1137
1138 void WebViewImpl::didUpdateLayout(WebFrameImpl* webframe)
1139 {
1140 if (!m_client || webframe != mainFrameImpl())
1141 return;
1142
1143 if (m_autoSize) {
1144 WebSize frameSize = mainFrameImpl()->frame()->view()->frameRect().size() ;
1145 if (frameSize != m_lastAutoSize) {
1146 m_lastAutoSize = frameSize;
1147 m_client->autoSizeChanged(frameSize);
1148 }
1149 }
1150
1151 m_client->didUpdateLayout();
1152 }
1153
1056 void WebViewImpl::willEndLiveResize() 1154 void WebViewImpl::willEndLiveResize()
1057 { 1155 {
1058 if (mainFrameImpl() && mainFrameImpl()->frameView()) 1156 if (mainFrameImpl() && mainFrameImpl()->frameView())
1059 mainFrameImpl()->frameView()->willEndLiveResize(); 1157 mainFrameImpl()->frameView()->willEndLiveResize();
1060 1158
1061 Frame* frame = mainFrameImpl()->frame(); 1159 Frame* frame = mainFrameImpl()->frame();
1062 WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromF rame(frame); 1160 WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromF rame(frame);
1063 if (pluginContainer) 1161 if (pluginContainer)
1064 pluginContainer->willEndLiveResize(); 1162 pluginContainer->willEndLiveResize();
1065 } 1163 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 gc.translate(IntSize(0, bitmapHeight)); 1293 gc.translate(IntSize(0, bitmapHeight));
1196 gc.scale(FloatSize(1.0f, -1.0f)); 1294 gc.scale(FloatSize(1.0f, -1.0f));
1197 // Use invertRect in next line, so that transform above inverts it back to 1295 // Use invertRect in next line, so that transform above inverts it back to
1198 // desired destination rect. 1296 // desired destination rect.
1199 gc.drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, invertRect.lo cation()); 1297 gc.drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, invertRect.lo cation());
1200 gc.restore(); 1298 gc.restore();
1201 } 1299 }
1202 } 1300 }
1203 #endif 1301 #endif
1204 1302
1205 void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect) 1303 void WebViewImpl::paint(WebCanvas* canvas, const WebRect& unscaledRect)
1206 { 1304 {
1305 WebRect rect = unscaledRect;
1306
1307 if (m_autoSize && !m_size.isEmpty() && !m_lastAutoSize.isEmpty()) {
darin (slow to review) 2011/11/28 16:50:40 what about the case where the page is rendered thr
levin 2011/11/28 18:34:01 That case is right below. It writes into the same
1308 // In autosize mode, scale the rendered content size to match what the w idget wants.
1309 // This is only to compensate for a very short term intermediate state w hile the widget
1310 // is being resized (animated) to match the desired size (so mouse click , hover, etc.
1311 // are not adjusted in a similar manner).
1312 float scaleX = static_cast<float>(m_size.width) / m_lastAutoSize.width;
1313 float scaleY = static_cast<float>(m_size.height) / m_lastAutoSize.height ;
1314
1315 canvas->save();
1316 canvas->scale(scaleX, scaleY);
1317 rect.x = static_cast<int>(rect.x / scaleX);
1318 rect.width = static_cast<int>(rect.width / scaleX);
1319 rect.y = static_cast<int>(rect.y / scaleY);
1320 rect.height = static_cast<int>(rect.height / scaleY);
1321 }
1322
1207 if (isAcceleratedCompositingActive()) { 1323 if (isAcceleratedCompositingActive()) {
1208 #if USE(ACCELERATED_COMPOSITING) 1324 #if USE(ACCELERATED_COMPOSITING)
1209 // If a canvas was passed in, we use it to grab a copy of the 1325 // If a canvas was passed in, we use it to grab a copy of the
1210 // freshly-rendered pixels. 1326 // freshly-rendered pixels.
1211 if (canvas) { 1327 if (canvas) {
1212 // Clip rect to the confines of the rootLayerTexture. 1328 // Clip rect to the confines of the rootLayerTexture.
1213 IntRect resizeRect(rect); 1329 IntRect resizeRect(rect);
1214 resizeRect.intersect(IntRect(IntPoint(0, 0), m_layerTreeHost->viewpo rtSize())); 1330 resizeRect.intersect(IntRect(IntPoint(0, 0), m_layerTreeHost->viewpo rtSize()));
1215 doPixelReadbackToCanvas(canvas, resizeRect); 1331 doPixelReadbackToCanvas(canvas, resizeRect);
1216 } 1332 }
1217 #endif 1333 #endif
1218 } else { 1334 } else {
1219 double paintStart = currentTime(); 1335 double paintStart = currentTime();
1220 WebFrameImpl* webframe = mainFrameImpl(); 1336 WebFrameImpl* webframe = mainFrameImpl();
1221 if (webframe) 1337 if (webframe)
1222 webframe->paint(canvas, rect); 1338 webframe->paint(canvas, rect);
1223 double paintEnd = currentTime(); 1339 double paintEnd = currentTime();
1224 double pixelsPerSec = (rect.width * rect.height) / (paintEnd - paintStar t); 1340 double pixelsPerSec = (rect.width * rect.height) / (paintEnd - paintStar t);
1225 PlatformSupport::histogramCustomCounts("Renderer4.SoftwarePaintDurationM S", (paintEnd - paintStart) * 1000, 0, 120, 30); 1341 PlatformSupport::histogramCustomCounts("Renderer4.SoftwarePaintDurationM S", (paintEnd - paintStart) * 1000, 0, 120, 30);
1226 PlatformSupport::histogramCustomCounts("Renderer4.SoftwarePaintMegapixPe rSecond", pixelsPerSec / 1000000, 10, 210, 30); 1342 PlatformSupport::histogramCustomCounts("Renderer4.SoftwarePaintMegapixPe rSecond", pixelsPerSec / 1000000, 10, 210, 30);
1227 } 1343 }
1344
1345 if (m_autoSize)
1346 canvas->restore();
1228 } 1347 }
1229 1348
1230 void WebViewImpl::themeChanged() 1349 void WebViewImpl::themeChanged()
1231 { 1350 {
1232 if (!page()) 1351 if (!page())
1233 return; 1352 return;
1234 FrameView* view = page()->mainFrame()->view(); 1353 FrameView* view = page()->mainFrame()->view();
1235 1354
1236 WebRect damagedRect(0, 0, m_size.width, m_size.height); 1355 WebRect damagedRect(0, 0, m_size.width, m_size.height);
1237 view->invalidateRect(damagedRect); 1356 view->invalidateRect(damagedRect);
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 2153
2035 #if USE(ACCELERATED_COMPOSITING) 2154 #if USE(ACCELERATED_COMPOSITING)
2036 // Also notify the base layer, which RenderLayerCompositor does not see. 2155 // Also notify the base layer, which RenderLayerCompositor does not see.
2037 if (m_nonCompositedContentHost) { 2156 if (m_nonCompositedContentHost) {
2038 m_nonCompositedContentHost->topLevelRootLayer()->deviceOrPageScaleFactor Changed(); 2157 m_nonCompositedContentHost->topLevelRootLayer()->deviceOrPageScaleFactor Changed();
2039 updateLayerTreeViewport(); 2158 updateLayerTreeViewport();
2040 } 2159 }
2041 #endif 2160 #endif
2042 } 2161 }
2043 2162
2163 void WebViewImpl::enableAutoSizeMode(bool enable, const WebSize& minSize, const WebSize& maxSize)
2164 {
2165 ASSERT(!enable || !minSize.isEmpty());
2166 ASSERT(minSize.width <= maxSize.width);
2167 ASSERT(minSize.height <= maxSize.height);
2168
2169 m_autoSize = enable;
2170 m_minAutoSize = minSize;
2171 m_maxAutoSize = maxSize;
2172
2173 FrameView* frameView = mainFrameImpl()->frame()->view();
2174 frameView->setNeedsLayout();
2175 frameView->scheduleRelayout();
2176 }
2177
2044 void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScal e) 2178 void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScal e)
2045 { 2179 {
2046 m_minimumPageScaleFactor = min(max(minPageScale, minPageScaleFactor), maxPag eScaleFactor) * deviceScaleFactor(); 2180 m_minimumPageScaleFactor = min(max(minPageScale, minPageScaleFactor), maxPag eScaleFactor) * deviceScaleFactor();
2047 m_maximumPageScaleFactor = max(min(maxPageScale, maxPageScaleFactor), minPag eScaleFactor) * deviceScaleFactor(); 2181 m_maximumPageScaleFactor = max(min(maxPageScale, maxPageScaleFactor), minPag eScaleFactor) * deviceScaleFactor();
2048 2182
2049 if (m_size.width && mainFrame() && mainFrame()->contentsSize().width) { 2183 if (m_size.width && mainFrame() && mainFrame()->contentsSize().width) {
2050 // Limit page scaling down to the document width. 2184 // Limit page scaling down to the document width.
2051 int viewWidth = m_size.width; 2185 int viewWidth = m_size.width;
2052 int unscaledContentWidth = mainFrame()->contentsSize().width / pageScale Factor(); 2186 int unscaledContentWidth = mainFrame()->contentsSize().width / pageScale Factor();
2053 m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<flo at>(viewWidth) / unscaledContentWidth); 2187 m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<flo at>(viewWidth) / unscaledContentWidth);
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 } 3143 }
3010 3144
3011 #if ENABLE(GESTURE_RECOGNIZER) 3145 #if ENABLE(GESTURE_RECOGNIZER)
3012 void WebViewImpl::resetGestureRecognizer() 3146 void WebViewImpl::resetGestureRecognizer()
3013 { 3147 {
3014 m_gestureRecognizer->reset(); 3148 m_gestureRecognizer->reset();
3015 } 3149 }
3016 #endif 3150 #endif
3017 3151
3018 } // namespace WebKit 3152 } // namespace WebKit
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WebViewImpl.h ('k') | Tools/DumpRenderTree/chromium/WebViewHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698