Index: ios/web/public/web_state/page_display_state.mm |
diff --git a/ios/web/public/web_state/page_display_state.mm b/ios/web/public/web_state/page_display_state.mm |
index 378456b90118575f576be659f2cfa768a0462aac..6064fc5b7fd45622c271cfeff1d12fea7db93978 100644 |
--- a/ios/web/public/web_state/page_display_state.mm |
+++ b/ios/web/public/web_state/page_display_state.mm |
@@ -19,6 +19,12 @@ |
inline bool StateValuesAreEqual(double value1, double value2) { |
return std::isnan(value1) ? std::isnan(value2) : value1 == value2; |
} |
+// Returns the double stored under |key| in |serialization|, or NAN if it is not |
+// set. |
+inline double GetValue(NSString* key, NSDictionary* serialization) { |
+ NSNumber* value = serialization[key]; |
+ return value ? [value doubleValue] : NAN; |
+} |
} // namespace |
PageScrollState::PageScrollState() : offset_x_(NAN), offset_y_(NAN) { |
@@ -44,6 +50,16 @@ inline bool StateValuesAreEqual(double value1, double value2) { |
return !(*this == other); |
} |
+NSString* PageScrollState::XOffsetKey() { |
+ static NSString* const kXOffsetKey = @"scrollX"; |
+ return kXOffsetKey; |
+} |
+ |
+NSString* PageScrollState::YOffsetKey() { |
+ static NSString* const kYOffsetKey = @"scrollY"; |
+ return kYOffsetKey; |
+} |
+ |
PageZoomState::PageZoomState() |
: minimum_zoom_scale_(NAN), maximum_zoom_scale_(NAN), zoom_scale_(NAN) { |
} |
@@ -76,6 +92,24 @@ inline bool StateValuesAreEqual(double value1, double value2) { |
return !(*this == other); |
} |
+// static |
+NSString* PageZoomState::MinZoomKey() { |
+ static NSString* const kMinZoomKey = @"minZoom"; |
+ return kMinZoomKey; |
+} |
+ |
+// static |
+NSString* PageZoomState::MaxZoomKey() { |
+ static NSString* const kMaxZoomKey = @"maxZoom"; |
+ return kMaxZoomKey; |
+} |
+ |
+// static |
+NSString* PageZoomState::ZoomKey() { |
+ static NSString* const kZoomKey = @"zoom"; |
+ return kZoomKey; |
+} |
+ |
PageDisplayState::PageDisplayState() { |
} |
@@ -93,6 +127,13 @@ inline bool StateValuesAreEqual(double value1, double value2) { |
zoom_state_(minimum_zoom_scale, maximum_zoom_scale, zoom_scale) { |
} |
+PageDisplayState::PageDisplayState(NSDictionary* serialization) |
+ : PageDisplayState(GetValue(PageScrollState::XOffsetKey(), serialization), |
+ GetValue(PageScrollState::YOffsetKey(), serialization), |
+ GetValue(PageZoomState::MinZoomKey(), serialization), |
+ GetValue(PageZoomState::MaxZoomKey(), serialization), |
+ GetValue(PageZoomState::ZoomKey(), serialization)) {} |
+ |
PageDisplayState::~PageDisplayState() { |
} |
@@ -109,4 +150,26 @@ inline bool StateValuesAreEqual(double value1, double value2) { |
return !(*this == other); |
} |
+NSDictionary* PageDisplayState::GetSerialization() const { |
+ return @{ |
+ PageScrollState::XOffsetKey() : @(scroll_state_.offset_x()), |
+ PageScrollState::YOffsetKey() : @(scroll_state_.offset_y()), |
+ PageZoomState::MinZoomKey() : @(zoom_state_.minimum_zoom_scale()), |
+ PageZoomState::MaxZoomKey() : @(zoom_state_.maximum_zoom_scale()), |
+ PageZoomState::ZoomKey() : @(zoom_state_.zoom_scale()) |
+ }; |
+} |
+ |
+NSString* PageDisplayState::GetDescription() const { |
+ NSString* const kPageScrollStateDescriptionFormat = |
+ @"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), " |
+ @"zoomScale:%0.2f }"; |
+ return [NSString stringWithFormat:kPageScrollStateDescriptionFormat, |
+ scroll_state_.offset_x(), |
+ scroll_state_.offset_y(), |
+ zoom_state_.minimum_zoom_scale(), |
+ zoom_state_.maximum_zoom_scale(), |
+ zoom_state_.zoom_scale()]; |
+} |
+ |
} // namespace web |