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

Side by Side Diff: Source/core/frame/PinchViewport.cpp

Issue 263853008: Added pinch viewport offset to history item. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Feedback addressed + small fix for broken unit test Created 6 years, 7 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 using WebCore::FrameHost; 59 using WebCore::FrameHost;
60 using WebCore::GraphicsLayer; 60 using WebCore::GraphicsLayer;
61 using WebCore::GraphicsLayerFactory; 61 using WebCore::GraphicsLayerFactory;
62 62
63 namespace WebCore { 63 namespace WebCore {
64 64
65 PinchViewport::PinchViewport(FrameHost& owner) 65 PinchViewport::PinchViewport(FrameHost& owner)
66 : m_frameHost(owner) 66 : m_frameHost(owner)
67 , m_scale(1) 67 , m_scale(1)
68 { 68 {
69 } 69 }
abarth-chromium 2014/05/09 14:11:23 Maybe call reset() in the constructor to keep the
bokan 2014/05/09 14:32:57 Done.
70 70
71 PinchViewport::~PinchViewport() { } 71 PinchViewport::~PinchViewport() { }
72 72
73 void PinchViewport::setSize(const IntSize& size) 73 void PinchViewport::setSize(const IntSize& size)
74 { 74 {
75 ASSERT(mainFrame() && mainFrame()->view()); 75 ASSERT(mainFrame() && mainFrame()->view());
76 76
77 if (!m_innerViewportContainerLayer || !m_innerViewportScrollLayer) 77 if (!m_innerViewportContainerLayer || !m_innerViewportScrollLayer)
78 return; 78 return;
79 79
80 if (m_size == size) 80 if (m_size == size)
81 return; 81 return;
82 82
83 m_size = size; 83 m_size = size;
84 m_innerViewportContainerLayer->setSize(m_size); 84 m_innerViewportContainerLayer->setSize(m_size);
85 85
86 // Make sure we clamp the offset to within the new bounds. 86 // Make sure we clamp the offset to within the new bounds.
87 setLocation(m_offset); 87 setLocation(m_offset);
88 88
89 // Need to re-compute sizes for the overlay scrollbars. 89 // Need to re-compute sizes for the overlay scrollbars.
90 setupScrollbar(WebScrollbar::Horizontal); 90 setupScrollbar(WebScrollbar::Horizontal);
91 setupScrollbar(WebScrollbar::Vertical); 91 setupScrollbar(WebScrollbar::Vertical);
92 } 92 }
93 93
94 void PinchViewport::reset()
95 {
96 setLocation(FloatPoint(0, 0));
abarth-chromium 2014/05/09 14:11:23 setLocation(FloatPoint());
bokan 2014/05/09 14:32:57 Done.
97 setScale(1);
98 }
99
94 void PinchViewport::mainFrameDidChangeSize() 100 void PinchViewport::mainFrameDidChangeSize()
95 { 101 {
96 // In unit tests we may not have initialized the layer tree. 102 // In unit tests we may not have initialized the layer tree.
97 if (m_innerViewportScrollLayer) 103 if (m_innerViewportScrollLayer)
98 m_innerViewportScrollLayer->setSize(contentsSize()); 104 m_innerViewportScrollLayer->setSize(contentsSize());
99 105
100 // Make sure the viewport's offset is clamped within the newly sized main fr ame. 106 // Make sure the viewport's offset is clamped within the newly sized main fr ame.
101 setLocation(m_offset); 107 setLocation(m_offset);
102 } 108 }
103 109
104 FloatRect PinchViewport::visibleRect() const 110 FloatRect PinchViewport::visibleRect() const
105 { 111 {
106 FloatSize scaledSize(m_size); 112 FloatSize scaledSize(m_size);
107 scaledSize.scale(1 / m_scale); 113 scaledSize.scale(1 / m_scale);
108 return FloatRect(m_offset, scaledSize); 114 return FloatRect(m_offset, scaledSize);
109 } 115 }
110 116
111 void PinchViewport::setLocation(const FloatPoint& newLocation) 117 void PinchViewport::setLocation(const FloatPoint& newLocation)
112 { 118 {
113 FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation)); 119 FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation));
114 120
115 if (clampedOffset == m_offset) 121 if (clampedOffset == m_offset)
116 return; 122 return;
117 123
118 m_offset = clampedOffset; 124 m_offset = clampedOffset;
119 125
120 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator( ); 126 ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator( );
121 ASSERT(coordinator); 127 ASSERT(coordinator);
122 coordinator->scrollableAreaScrollLayerDidChange(this); 128 coordinator->scrollableAreaScrollLayerDidChange(this);
129
130 mainFrame()->loader().saveScrollState();
123 } 131 }
124 132
125 void PinchViewport::setScale(float scale) 133 void PinchViewport::setScale(float scale)
126 { 134 {
135 if (scale == m_scale)
136 return;
137
127 m_scale = scale; 138 m_scale = scale;
128 139
140 mainFrame()->loader().saveScrollState();
141
129 // Old-style pinch sets scale here but we shouldn't call into the 142 // Old-style pinch sets scale here but we shouldn't call into the
130 // clamping code below. 143 // clamping code below.
131 if (!m_innerViewportScrollLayer) 144 if (!m_innerViewportScrollLayer)
132 return; 145 return;
133 146
134 // Ensure we clamp so we remain within the bounds. 147 // Ensure we clamp so we remain within the bounds.
135 setLocation(visibleRect().location()); 148 setLocation(visibleRect().location());
149
150 // TODO: We should probably be calling scaleDidChange type functions here.
151 // see Page::setPageScaleFactor.
136 } 152 }
137 153
138 // Modifies the top of the graphics layer tree to add layers needed to support 154 // Modifies the top of the graphics layer tree to add layers needed to support
139 // the inner/outer viewport fixed-position model for pinch zoom. When finished, 155 // the inner/outer viewport fixed-position model for pinch zoom. When finished,
140 // the tree will look like this (with * denoting added layers): 156 // the tree will look like this (with * denoting added layers):
141 // 157 //
142 // *innerViewportContainerLayer (fixed pos container) 158 // *innerViewportContainerLayer (fixed pos container)
143 // +- *pageScaleLayer 159 // +- *pageScaleLayer
144 // | +- *innerViewportScrollLayer 160 // | +- *innerViewportScrollLayer
145 // | +-- overflowControlsHostLayer (root layer) 161 // | +-- overflowControlsHostLayer (root layer)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) { 397 } else if (graphicsLayer == m_overlayScrollbarVertical.get()) {
382 name = "Overlay Scrollbar Vertical Layer"; 398 name = "Overlay Scrollbar Vertical Layer";
383 } else { 399 } else {
384 ASSERT_NOT_REACHED(); 400 ASSERT_NOT_REACHED();
385 } 401 }
386 402
387 return name; 403 return name;
388 } 404 }
389 405
390 } // namespace WebCore 406 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698