clang/win/asan: Remove /fallback and enable warnings-as-errors.
[chromium-blink-merge.git] / ios / web / public / web_state / page_display_state.h
blob7098e2fc5e12f5c1bc90bcf797ae2a2510ad0184
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_
8 namespace web {
10 // Class used to represent the scrolling offset of a webview.
11 class PageScrollState {
12 public:
13 // Default constructor. Initializes scroll offsets to NAN.
14 PageScrollState();
15 // Constructor with initial values.
16 PageScrollState(double offset_x, double offset_y);
17 ~PageScrollState();
19 // The scroll offset is valid if its x and y values are both non-NAN.
20 bool IsValid() const;
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;
32 private:
33 // The x value of the page's UIScrollView contentOffset.
34 double offset_x_;
35 // The y value of the page's UIScrollView contentOffset.
36 double offset_y_;
39 // Class used to represent the scrolling offset and the zoom scale of a webview.
40 class PageZoomState {
41 public:
42 // Default constructor. Initializes scroll offsets and zoom scales to NAN.
43 PageZoomState();
44 // Constructor with initial values.
45 PageZoomState(double minimum_zoom_scale,
46 double maximum_zoom_scale,
47 double zoom_scale);
48 ~PageZoomState();
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.
54 bool IsValid() const;
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_;
67 // Accessors.
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;
83 private:
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.
89 double zoom_scale_;
92 // Class used to represent the scroll offset and zoom scale of a webview.
93 class PageDisplayState {
94 public:
95 // Default constructor. Initializes scroll offsets and zoom scales to NAN.
96 PageDisplayState();
97 // Constructor with initial values.
98 PageDisplayState(const PageScrollState& scroll_state,
99 const PageZoomState& zoom_state);
100 PageDisplayState(double offset_x,
101 double offset_y,
102 double minimum_zoom_scale,
103 double maximum_zoom_scale,
104 double zoom_scale);
105 ~PageDisplayState();
107 // PageScrollStates cannot be applied until the scroll offset and zoom scale
108 // are both valid.
109 bool IsValid() const;
111 // Accessors.
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;
127 private:
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_;
134 } // namespace web
136 #endif // IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_