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

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

Issue 1814013002: Visual viewport API initial implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make visualviewportchanged per frame + other review feedback Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 { 78 {
79 sendUMAMetrics(); 79 sendUMAMetrics();
80 } 80 }
81 81
82 DEFINE_TRACE(VisualViewport) 82 DEFINE_TRACE(VisualViewport)
83 { 83 {
84 visitor->trace(m_frameHost); 84 visitor->trace(m_frameHost);
85 ScrollableArea::trace(visitor); 85 ScrollableArea::trace(visitor);
86 } 86 }
87 87
88 void VisualViewport::updateLayoutIgnorePendingStylesheets()
89 {
90 if (!mainFrame())
91 return;
92
93 Document* document = mainFrame()->document();
94 if (!document)
95 return;
96
97 document->updateLayoutIgnorePendingStylesheets();
esprehn 2016/03/31 05:15:37 we would normally write: if (Document* document =
ymalik 2016/04/01 17:15:37 Done.
98 return;
esprehn 2016/03/31 05:15:37 remove return
ymalik 2016/04/01 17:15:36 Done.
99 }
100
101 void VisualViewport::enqueueChangedEvent()
102 {
103 if (RuntimeEnabledFeatures::visualViewportAPIEnabled()) {
esprehn 2016/03/31 05:15:37 early return instead of wrapping the whole functio
ymalik 2016/04/01 17:15:36 Done.
104 if (Document* document = mainFrame()->document())
105 document->enqueueVisualViewportChangedEvent();
106 }
107 }
108
88 void VisualViewport::setSize(const IntSize& size) 109 void VisualViewport::setSize(const IntSize& size)
89 { 110 {
90 if (m_size == size) 111 if (m_size == size)
91 return; 112 return;
92 113
93 TRACE_EVENT2("blink", "VisualViewport::setSize", "width", size.width(), "hei ght", size.height()); 114 TRACE_EVENT2("blink", "VisualViewport::setSize", "width", size.width(), "hei ght", size.height());
94 bool widthDidChange = size.width() != m_size.width(); 115 bool widthDidChange = size.width() != m_size.width();
95 m_size = size; 116 m_size = size;
96 117
97 if (m_innerViewportContainerLayer) { 118 if (m_innerViewportContainerLayer) {
98 m_innerViewportContainerLayer->setSize(FloatSize(m_size)); 119 m_innerViewportContainerLayer->setSize(FloatSize(m_size));
99 120
100 // Need to re-compute sizes for the overlay scrollbars. 121 // Need to re-compute sizes for the overlay scrollbars.
101 initializeScrollbars(); 122 initializeScrollbars();
102 } 123 }
103 124
104 if (!mainFrame()) 125 if (!mainFrame())
105 return; 126 return;
106 127
128 enqueueChangedEvent();
129
107 bool autosizerNeedsUpdating = widthDidChange 130 bool autosizerNeedsUpdating = widthDidChange
108 && mainFrame()->settings() 131 && mainFrame()->settings()
109 && mainFrame()->settings()->textAutosizingEnabled(); 132 && mainFrame()->settings()->textAutosizingEnabled();
110 133
111 if (autosizerNeedsUpdating) { 134 if (autosizerNeedsUpdating) {
112 // This needs to happen after setting the m_size member since it'll be r ead in the update call. 135 // This needs to happen after setting the m_size member since it'll be r ead in the update call.
113 if (TextAutosizer* textAutosizer = mainFrame()->document()->textAutosize r()) 136 if (TextAutosizer* textAutosizer = mainFrame()->document()->textAutosize r())
114 textAutosizer->updatePageInfoInAllFrames(); 137 textAutosizer->updatePageInfoInAllFrames();
115 } 138 }
116 } 139 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 void VisualViewport::move(const FloatSize& delta) 205 void VisualViewport::move(const FloatSize& delta)
183 { 206 {
184 setLocation(m_offset + delta); 207 setLocation(m_offset + delta);
185 } 208 }
186 209
187 void VisualViewport::setScale(float scale) 210 void VisualViewport::setScale(float scale)
188 { 211 {
189 setScaleAndLocation(scale, m_offset); 212 setScaleAndLocation(scale, m_offset);
190 } 213 }
191 214
215 double VisualViewport::scrollLeft()
216 {
217 updateLayoutIgnorePendingStylesheets();
218
219 return visibleRect().x();
220 }
221
222 double VisualViewport::scrollTop()
223 {
224 updateLayoutIgnorePendingStylesheets();
225
226 return visibleRect().y();
227 }
228
229 void VisualViewport::setScrollLeft(double x)
230 {
231 updateLayoutIgnorePendingStylesheets();
232
233 setLocation(FloatPoint(x, visibleRect().y()));
234 }
235
236 void VisualViewport::setScrollTop(double y)
237 {
238 updateLayoutIgnorePendingStylesheets();
239
240 setLocation(FloatPoint(visibleRect().x(), y));
241 }
242
243 double VisualViewport::clientWidth()
244 {
245 updateLayoutIgnorePendingStylesheets();
246
247 return visibleRect().width();
248 }
249
250 double VisualViewport::clientHeight()
251 {
252 updateLayoutIgnorePendingStylesheets();
253
254 return visibleRect().height();
255 }
256
257 double VisualViewport::pageScale()
258 {
259 updateLayoutIgnorePendingStylesheets();
260
261 return m_scale;
262 }
263
192 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location ) 264 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location )
193 { 265 {
194 if (!mainFrame()) 266 if (!mainFrame())
195 return; 267 return;
196 268
197 bool valuesChanged = false; 269 bool valuesChanged = false;
198 270
199 if (scale != m_scale) { 271 if (scale != m_scale) {
200 m_scale = scale; 272 m_scale = scale;
201 valuesChanged = true; 273 valuesChanged = true;
(...skipping 15 matching lines...) Expand all
217 document->enqueueScrollEventForNode(document); 289 document->enqueueScrollEventForNode(document);
218 } 290 }
219 291
220 mainFrame()->loader().client()->didChangeScrollOffset(); 292 mainFrame()->loader().client()->didChangeScrollOffset();
221 valuesChanged = true; 293 valuesChanged = true;
222 } 294 }
223 295
224 if (!valuesChanged) 296 if (!valuesChanged)
225 return; 297 return;
226 298
299 enqueueChangedEvent();
300
227 InspectorInstrumentation::didUpdateLayout(mainFrame()); 301 InspectorInstrumentation::didUpdateLayout(mainFrame());
228 mainFrame()->loader().saveScrollState(); 302 mainFrame()->loader().saveScrollState();
229 303
230 clampToBoundaries(); 304 clampToBoundaries();
231 } 305 }
232 306
233 bool VisualViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoi nt& anchor) 307 bool VisualViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoi nt& anchor)
234 { 308 {
235 const float oldPageScale = scale(); 309 const float oldPageScale = scale();
236 const float newPageScale = frameHost().chromeClient().clampPageScaleFactorTo Limits( 310 const float newPageScale = frameHost().chromeClient().clampPageScaleFactorTo Limits(
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } else if (graphicsLayer == m_rootTransformLayer) { 817 } else if (graphicsLayer == m_rootTransformLayer) {
744 name = "Root Transform Layer"; 818 name = "Root Transform Layer";
745 } else { 819 } else {
746 ASSERT_NOT_REACHED(); 820 ASSERT_NOT_REACHED();
747 } 821 }
748 822
749 return name; 823 return name;
750 } 824 }
751 825
752 } // namespace blink 826 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698