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

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: Created 4 years, 9 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 { 80 {
81 sendUMAMetrics(); 81 sendUMAMetrics();
82 } 82 }
83 83
84 DEFINE_TRACE(VisualViewport) 84 DEFINE_TRACE(VisualViewport)
85 { 85 {
86 visitor->trace(m_frameHost); 86 visitor->trace(m_frameHost);
87 ScrollableArea::trace(visitor); 87 ScrollableArea::trace(visitor);
88 } 88 }
89 89
90 void VisualViewport::updateLayoutIgnorePendingStylesheets()
91 {
92 if (!mainFrame())
93 return;
94
95 Document* document = mainFrame()->document();
96 if (!document)
97 return;
98
99 document->updateLayoutIgnorePendingStylesheets();
100 return;
101 }
102
90 void VisualViewport::setSize(const IntSize& size) 103 void VisualViewport::setSize(const IntSize& size)
91 { 104 {
92 if (m_size == size) 105 if (m_size == size)
93 return; 106 return;
94 107
95 TRACE_EVENT2("blink", "VisualViewport::setSize", "width", size.width(), "hei ght", size.height()); 108 TRACE_EVENT2("blink", "VisualViewport::setSize", "width", size.width(), "hei ght", size.height());
96 bool widthDidChange = size.width() != m_size.width(); 109 bool widthDidChange = size.width() != m_size.width();
97 m_size = size; 110 m_size = size;
98 111
99 if (m_innerViewportContainerLayer) { 112 if (m_innerViewportContainerLayer) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void VisualViewport::move(const FloatSize& delta) 197 void VisualViewport::move(const FloatSize& delta)
185 { 198 {
186 setLocation(m_offset + delta); 199 setLocation(m_offset + delta);
187 } 200 }
188 201
189 void VisualViewport::setScale(float scale) 202 void VisualViewport::setScale(float scale)
190 { 203 {
191 setScaleAndLocation(scale, m_offset); 204 setScaleAndLocation(scale, m_offset);
192 } 205 }
193 206
207 double VisualViewport::scrollLeft()
208 {
209 updateLayoutIgnorePendingStylesheets();
ymalik 2016/03/18 13:30:57 @bokan, I am not sure whether we need to call upda
bokan 2016/03/18 16:05:07 I think we need it. The reason being that the visu
ymalik 2016/03/22 16:35:06 Acknowledged.
210
211 return visibleRect().x();
212 }
213
214 double VisualViewport::scrollTop()
215 {
216 updateLayoutIgnorePendingStylesheets();
217
218 return visibleRect().y();
219 }
220
221 void VisualViewport::setScrollLeft(double x)
222 {
223 updateLayoutIgnorePendingStylesheets();
224
225 DoublePoint layoutPos(x, visibleRect().y());
226 setScrollPosition(layoutPos, ProgrammaticScroll, ScrollBehaviorAuto);
227 }
228
229 void VisualViewport::setScrollTop(double y)
230 {
231 updateLayoutIgnorePendingStylesheets();
232
233 DoublePoint layoutPos(visibleRect().x(), y);
234 setScrollPosition(layoutPos, ProgrammaticScroll, ScrollBehaviorAuto);
235 }
236
237 double VisualViewport::clientWidth()
238 {
239 updateLayoutIgnorePendingStylesheets();
240
241 return visibleRect().width();
242 }
243
244 double VisualViewport::clientHeight()
245 {
246 updateLayoutIgnorePendingStylesheets();
247
248 return visibleRect().height();
249 }
250
251 double VisualViewport::pageScale()
252 {
253 updateLayoutIgnorePendingStylesheets();
254
255 return m_scale;
256 }
257
194 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location ) 258 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location )
195 { 259 {
196 if (!mainFrame()) 260 if (!mainFrame())
197 return; 261 return;
198 262
199 bool valuesChanged = false; 263 bool valuesChanged = false;
200 264
201 if (scale != m_scale) { 265 if (scale != m_scale) {
202 m_scale = scale; 266 m_scale = scale;
203 valuesChanged = true; 267 valuesChanged = true;
(...skipping 15 matching lines...) Expand all
219 document->enqueueScrollEventForNode(document); 283 document->enqueueScrollEventForNode(document);
220 } 284 }
221 285
222 mainFrame()->loader().client()->didChangeScrollOffset(); 286 mainFrame()->loader().client()->didChangeScrollOffset();
223 valuesChanged = true; 287 valuesChanged = true;
224 } 288 }
225 289
226 if (!valuesChanged) 290 if (!valuesChanged)
227 return; 291 return;
228 292
293 if (RuntimeEnabledFeatures::visualViewportAPIEnabled()) {
294 if (Document* document = mainFrame()->document()) {
295 if (document->documentElement())
296 document->documentElement()->dispatchViewportChangedEvent();
297 }
298 }
299
229 InspectorInstrumentation::didUpdateLayout(mainFrame()); 300 InspectorInstrumentation::didUpdateLayout(mainFrame());
230 mainFrame()->loader().saveScrollState(); 301 mainFrame()->loader().saveScrollState();
231 302
232 clampToBoundaries(); 303 clampToBoundaries();
233 } 304 }
234 305
235 bool VisualViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoi nt& anchor) 306 bool VisualViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoi nt& anchor)
236 { 307 {
237 const float oldPageScale = scale(); 308 const float oldPageScale = scale();
238 const float newPageScale = frameHost().chromeClient().clampPageScaleFactorTo Limits( 309 const float newPageScale = frameHost().chromeClient().clampPageScaleFactorTo Limits(
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } else if (graphicsLayer == m_rootTransformLayer) { 810 } else if (graphicsLayer == m_rootTransformLayer) {
740 name = "Root Transform Layer"; 811 name = "Root Transform Layer";
741 } else { 812 } else {
742 ASSERT_NOT_REACHED(); 813 ASSERT_NOT_REACHED();
743 } 814 }
744 815
745 return name; 816 return name;
746 } 817 }
747 818
748 } // namespace blink 819 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698