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

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: s/Viewport.idl/VisualViewport.idl 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 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();
98 return;
99 }
100
101 void VisualViewport::dispatchChangedEvent()
102 {
103 if (RuntimeEnabledFeatures::visualViewportAPIEnabled()) {
104 if (Document* document = mainFrame()->document())
105 document->dispatchVisualViewportChangedEvent();
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 dispatchChangedEvent();
bokan 2016/03/22 18:30:29 Hmm...right now we're firing events synchronously.
ymalik 2016/03/22 21:28:20 Acknowledged.
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 DoublePoint layoutPos(x, visibleRect().y());
234 setScrollPosition(layoutPos, ProgrammaticScroll, ScrollBehaviorAuto);
235 }
236
237 void VisualViewport::setScrollTop(double y)
238 {
239 updateLayoutIgnorePendingStylesheets();
240
241 DoublePoint layoutPos(visibleRect().x(), y);
242 setScrollPosition(layoutPos, ProgrammaticScroll, ScrollBehaviorAuto);
243 }
244
245 double VisualViewport::clientWidth()
246 {
247 updateLayoutIgnorePendingStylesheets();
248
249 return visibleRect().width();
250 }
251
252 double VisualViewport::clientHeight()
253 {
254 updateLayoutIgnorePendingStylesheets();
255
256 return visibleRect().height();
257 }
258
259 double VisualViewport::pageScale()
260 {
261 updateLayoutIgnorePendingStylesheets();
262
263 return m_scale;
264 }
265
192 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location ) 266 void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location )
193 { 267 {
194 if (!mainFrame()) 268 if (!mainFrame())
195 return; 269 return;
196 270
197 bool valuesChanged = false; 271 bool valuesChanged = false;
198 272
199 if (scale != m_scale) { 273 if (scale != m_scale) {
200 m_scale = scale; 274 m_scale = scale;
201 valuesChanged = true; 275 valuesChanged = true;
(...skipping 15 matching lines...) Expand all
217 document->enqueueScrollEventForNode(document); 291 document->enqueueScrollEventForNode(document);
218 } 292 }
219 293
220 mainFrame()->loader().client()->didChangeScrollOffset(); 294 mainFrame()->loader().client()->didChangeScrollOffset();
221 valuesChanged = true; 295 valuesChanged = true;
222 } 296 }
223 297
224 if (!valuesChanged) 298 if (!valuesChanged)
225 return; 299 return;
226 300
301 dispatchChangedEvent();
302
227 InspectorInstrumentation::didUpdateLayout(mainFrame()); 303 InspectorInstrumentation::didUpdateLayout(mainFrame());
228 mainFrame()->loader().saveScrollState(); 304 mainFrame()->loader().saveScrollState();
229 305
230 clampToBoundaries(); 306 clampToBoundaries();
231 } 307 }
232 308
233 bool VisualViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoi nt& anchor) 309 bool VisualViewport::magnifyScaleAroundAnchor(float magnifyDelta, const FloatPoi nt& anchor)
234 { 310 {
235 const float oldPageScale = scale(); 311 const float oldPageScale = scale();
236 const float newPageScale = frameHost().chromeClient().clampPageScaleFactorTo Limits( 312 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) { 819 } else if (graphicsLayer == m_rootTransformLayer) {
744 name = "Root Transform Layer"; 820 name = "Root Transform Layer";
745 } else { 821 } else {
746 ASSERT_NOT_REACHED(); 822 ASSERT_NOT_REACHED();
747 } 823 }
748 824
749 return name; 825 return name;
750 } 826 }
751 827
752 } // namespace blink 828 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698