OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_ | 5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_ |
6 #define IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_ | 6 #define IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_ |
7 | 7 |
8 #import <Foundation/Foundation.h> | |
Eugene But (OOO till 7-30)
2017/02/03 01:52:34
This changes the header to Objective-C, so please
kkhorimoto
2017/02/03 02:47:23
Done.
| |
9 | |
8 namespace web { | 10 namespace web { |
9 | 11 |
10 // Class used to represent the scrolling offset of a webview. | 12 // Class used to represent the scrolling offset of a webview. |
11 class PageScrollState { | 13 class PageScrollState { |
12 public: | 14 public: |
13 // Default constructor. Initializes scroll offsets to NAN. | 15 // Default constructor. Initializes scroll offsets to NAN. |
14 PageScrollState(); | 16 PageScrollState(); |
15 // Constructor with initial values. | 17 // Constructor with initial values. |
16 PageScrollState(double offset_x, double offset_y); | 18 PageScrollState(double offset_x, double offset_y); |
17 ~PageScrollState(); | 19 ~PageScrollState(); |
18 | 20 |
19 // The scroll offset is valid if its x and y values are both non-NAN. | 21 // The scroll offset is valid if its x and y values are both non-NAN. |
20 bool IsValid() const; | 22 bool IsValid() const; |
21 | 23 |
22 // Accessors for scroll offsets and zoom scale. | 24 // Accessors for scroll offsets and zoom scale. |
23 double offset_x() const { return offset_x_; } | 25 double offset_x() const { return offset_x_; } |
24 void set_offset_x(double offset_x) { offset_x_ = offset_x; } | 26 void set_offset_x(double offset_x) { offset_x_ = offset_x; } |
25 double offset_y() const { return offset_y_; } | 27 double offset_y() const { return offset_y_; } |
26 void set_offset_y(double offset_y) { offset_y_ = offset_y; } | 28 void set_offset_y(double offset_y) { offset_y_ = offset_y; } |
27 | 29 |
28 // Comparator operators. | 30 // Comparator operators. |
29 bool operator==(const PageScrollState& other) const; | 31 bool operator==(const PageScrollState& other) const; |
30 bool operator!=(const PageScrollState& other) const; | 32 bool operator!=(const PageScrollState& other) const; |
31 | 33 |
34 // Serialization keys. | |
35 static NSString* XOffsetKey(); | |
Eugene But (OOO till 7-30)
2017/02/03 01:52:34
Should these keys be constants, like all other key
kkhorimoto
2017/02/03 02:47:23
Done.
| |
36 static NSString* YOffsetKey(); | |
37 | |
32 private: | 38 private: |
33 // The x value of the page's UIScrollView contentOffset. | 39 // The x value of the page's UIScrollView contentOffset. |
34 double offset_x_; | 40 double offset_x_; |
35 // The y value of the page's UIScrollView contentOffset. | 41 // The y value of the page's UIScrollView contentOffset. |
36 double offset_y_; | 42 double offset_y_; |
37 }; | 43 }; |
38 | 44 |
39 // Class used to represent the scrolling offset and the zoom scale of a webview. | 45 // Class used to represent the scrolling offset and the zoom scale of a webview. |
40 class PageZoomState { | 46 class PageZoomState { |
41 public: | 47 public: |
(...skipping 25 matching lines...) Expand all Loading... | |
67 void set_maximum_zoom_scale(double maximum_zoom_scale) { | 73 void set_maximum_zoom_scale(double maximum_zoom_scale) { |
68 maximum_zoom_scale_ = maximum_zoom_scale; | 74 maximum_zoom_scale_ = maximum_zoom_scale; |
69 } | 75 } |
70 double zoom_scale() const { return zoom_scale_; } | 76 double zoom_scale() const { return zoom_scale_; } |
71 void set_zoom_scale(double zoom_scale) { zoom_scale_ = zoom_scale; } | 77 void set_zoom_scale(double zoom_scale) { zoom_scale_ = zoom_scale; } |
72 | 78 |
73 // Comparator operators. | 79 // Comparator operators. |
74 bool operator==(const PageZoomState& other) const; | 80 bool operator==(const PageZoomState& other) const; |
75 bool operator!=(const PageZoomState& other) const; | 81 bool operator!=(const PageZoomState& other) const; |
76 | 82 |
83 // Serialization keys. | |
84 static NSString* MinZoomKey(); | |
85 static NSString* MaxZoomKey(); | |
86 static NSString* ZoomKey(); | |
87 | |
77 private: | 88 private: |
78 // The minimumZoomScale value of the page's UIScrollView. | 89 // The minimumZoomScale value of the page's UIScrollView. |
79 double minimum_zoom_scale_; | 90 double minimum_zoom_scale_; |
80 // The maximumZoomScale value of the page's UIScrollView. | 91 // The maximumZoomScale value of the page's UIScrollView. |
81 double maximum_zoom_scale_; | 92 double maximum_zoom_scale_; |
82 // The zoomScale value of the page's UIScrollView. | 93 // The zoomScale value of the page's UIScrollView. |
83 double zoom_scale_; | 94 double zoom_scale_; |
84 }; | 95 }; |
85 | 96 |
86 // Class used to represent the scroll offset and zoom scale of a webview. | 97 // Class used to represent the scroll offset and zoom scale of a webview. |
87 class PageDisplayState { | 98 class PageDisplayState { |
88 public: | 99 public: |
89 // Default constructor. Initializes scroll offsets and zoom scales to NAN. | 100 // Default constructor. Initializes scroll offsets and zoom scales to NAN. |
90 PageDisplayState(); | 101 PageDisplayState(); |
91 // Constructor with initial values. | 102 // Constructor with initial values. |
92 PageDisplayState(const PageScrollState& scroll_state, | 103 PageDisplayState(const PageScrollState& scroll_state, |
93 const PageZoomState& zoom_state); | 104 const PageZoomState& zoom_state); |
94 PageDisplayState(double offset_x, | 105 PageDisplayState(double offset_x, |
95 double offset_y, | 106 double offset_y, |
96 double minimum_zoom_scale, | 107 double minimum_zoom_scale, |
97 double maximum_zoom_scale, | 108 double maximum_zoom_scale, |
98 double zoom_scale); | 109 double zoom_scale); |
110 PageDisplayState(NSDictionary* serialization); | |
99 ~PageDisplayState(); | 111 ~PageDisplayState(); |
100 | 112 |
101 // PageScrollStates cannot be applied until the scroll offset and zoom scale | 113 // PageScrollStates cannot be applied until the scroll offset and zoom scale |
102 // are both valid. | 114 // are both valid. |
103 bool IsValid() const; | 115 bool IsValid() const; |
104 | 116 |
105 // Accessors. | 117 // Accessors. |
106 const PageScrollState& scroll_state() const { return scroll_state_; } | 118 const PageScrollState& scroll_state() const { return scroll_state_; } |
107 PageScrollState& scroll_state() { return scroll_state_; } | 119 PageScrollState& scroll_state() { return scroll_state_; } |
108 void set_scroll_state(const PageScrollState& scroll_state) { | 120 void set_scroll_state(const PageScrollState& scroll_state) { |
109 scroll_state_ = scroll_state; | 121 scroll_state_ = scroll_state; |
110 } | 122 } |
111 const PageZoomState& zoom_state() const { return zoom_state_; } | 123 const PageZoomState& zoom_state() const { return zoom_state_; } |
112 PageZoomState& zoom_state() { return zoom_state_; } | 124 PageZoomState& zoom_state() { return zoom_state_; } |
113 void set_zoom_state(const PageZoomState& zoom_state) { | 125 void set_zoom_state(const PageZoomState& zoom_state) { |
114 zoom_state_ = zoom_state; | 126 zoom_state_ = zoom_state; |
115 } | 127 } |
116 | 128 |
117 // Comparator operators. | 129 // Comparator operators. |
118 bool operator==(const PageDisplayState& other) const; | 130 bool operator==(const PageDisplayState& other) const; |
119 bool operator!=(const PageDisplayState& other) const; | 131 bool operator!=(const PageDisplayState& other) const; |
120 | 132 |
133 // Returns a serialized representation of the PageDisplayState. | |
134 NSDictionary* GetSerialization() const; | |
Eugene But (OOO till 7-30)
2017/02/03 01:52:34
Could you please add tests for these new functions
kkhorimoto
2017/02/03 02:47:23
Done.
| |
135 | |
136 // Returns a description string for the PageDisplayState. | |
137 NSString* GetDescription() const; | |
138 | |
121 private: | 139 private: |
122 // The scroll state for the page's UIScrollView. | 140 // The scroll state for the page's UIScrollView. |
123 PageScrollState scroll_state_; | 141 PageScrollState scroll_state_; |
124 // The zoom state for the page's UIScrollView. | 142 // The zoom state for the page's UIScrollView. |
125 PageZoomState zoom_state_; | 143 PageZoomState zoom_state_; |
126 }; | 144 }; |
127 | 145 |
128 } // namespace web | 146 } // namespace web |
129 | 147 |
130 #endif // IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_ | 148 #endif // IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_ |
OLD | NEW |