1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_
6 #define IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_
10 // Class used to represent the scrolling offset of a webview.
11 class PageScrollState
{
13 // Default constructor. Initializes scroll offsets to NAN.
15 // Constructor with initial values.
16 PageScrollState(double offset_x
, double offset_y
);
19 // The scroll offset is valid if its x and y values are both non-NAN.
22 // Accessors for scroll offsets and zoom scale.
23 double offset_x() const { return offset_x_
; }
24 void set_offset_x(double offset_x
) { offset_x_
= offset_x
; }
25 double offset_y() const { return offset_y_
; }
26 void set_offset_y(double offset_y
) { offset_y_
= offset_y
; }
28 // Comparator operators.
29 bool operator==(const PageScrollState
& other
) const;
30 bool operator!=(const PageScrollState
& other
) const;
33 // The x value of the page's UIScrollView contentOffset.
35 // The y value of the page's UIScrollView contentOffset.
39 // Class used to represent the scrolling offset and the zoom scale of a webview.
42 // Default constructor. Initializes scroll offsets and zoom scales to NAN.
44 // Constructor with initial values.
45 PageZoomState(double minimum_zoom_scale
,
46 double maximum_zoom_scale
,
50 // Non-legacy zoom scales are valid if all three values are non-NAN and the
51 // zoom scale is within the minimum and maximum scales. Legacy-format
52 // PageScrollStates are considered valid if the minimum and maximum scales
53 // are NAN and the zoom scale is greater than zero.
56 // PageScrollStates restored from the legacy serialization format make
57 // assumptions about the web view's implementation of zooming, and contain a
58 // non-NAN zoom scale and a NAN minimum and maximum scale. Legacy zoom scales
59 // can only be applied to CRWUIWebViewWebControllers.
60 bool IsLegacyFormat() const;
62 // Returns the allowed zoom scale range for this scroll state.
63 double GetMinMaxZoomDifference() const {
64 return maximum_zoom_scale_
- minimum_zoom_scale_
;
68 double minimum_zoom_scale() const { return minimum_zoom_scale_
; }
69 void set_minimum_zoom_scale(double minimum_zoom_scale
) {
70 minimum_zoom_scale_
= minimum_zoom_scale
;
72 double maximum_zoom_scale() const { return maximum_zoom_scale_
; }
73 void set_maximum_zoom_scale(double maximum_zoom_scale
) {
74 maximum_zoom_scale_
= maximum_zoom_scale
;
76 double zoom_scale() const { return zoom_scale_
; }
77 void set_zoom_scale(double zoom_scale
) { zoom_scale_
= zoom_scale
; }
79 // Comparator operators.
80 bool operator==(const PageZoomState
& other
) const;
81 bool operator!=(const PageZoomState
& other
) const;
84 // The minimumZoomScale value of the page's UIScrollView.
85 double minimum_zoom_scale_
;
86 // The maximumZoomScale value of the page's UIScrollView.
87 double maximum_zoom_scale_
;
88 // The zoomScale value of the page's UIScrollView.
92 // Class used to represent the scroll offset and zoom scale of a webview.
93 class PageDisplayState
{
95 // Default constructor. Initializes scroll offsets and zoom scales to NAN.
97 // Constructor with initial values.
98 PageDisplayState(const PageScrollState
& scroll_state
,
99 const PageZoomState
& zoom_state
);
100 PageDisplayState(double offset_x
,
102 double minimum_zoom_scale
,
103 double maximum_zoom_scale
,
107 // PageScrollStates cannot be applied until the scroll offset and zoom scale
109 bool IsValid() const;
112 const PageScrollState
& scroll_state() const { return scroll_state_
; }
113 PageScrollState
& scroll_state() { return scroll_state_
; }
114 void set_scroll_state(const PageScrollState
& scroll_state
) {
115 scroll_state_
= scroll_state
;
117 const PageZoomState
& zoom_state() const { return zoom_state_
; }
118 PageZoomState
& zoom_state() { return zoom_state_
; }
119 void set_zoom_state(const PageZoomState
& zoom_state
) {
120 zoom_state_
= zoom_state
;
123 // Comparator operators.
124 bool operator==(const PageDisplayState
& other
) const;
125 bool operator!=(const PageDisplayState
& other
) const;
128 // The scroll state for the page's UIScrollView.
129 PageScrollState scroll_state_
;
130 // The zoom state for the page's UIScrollView.
131 PageZoomState zoom_state_
;
136 #endif // IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_