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 #include "ios/web/public/web_state/page_display_state.h"
13 // - both |value1| and |value2| are NAN, or
14 // - |value1| and |value2| are equal non-NAN values.
15 inline bool StateValuesAreEqual(double value1, double value2) {
16 return std::isnan(value1) ? std::isnan(value2) : value1 == value2;
20 PageScrollState::PageScrollState() : offset_x_(NAN), offset_y_(NAN) {
23 PageScrollState::PageScrollState(double offset_x, double offset_y)
24 : offset_x_(offset_x), offset_y_(offset_y) {
27 PageScrollState::~PageScrollState() {
30 bool PageScrollState::IsValid() const {
31 return !std::isnan(offset_x_) && !std::isnan(offset_y_);
34 bool PageScrollState::operator==(const PageScrollState& other) const {
35 return StateValuesAreEqual(offset_x_, other.offset_x_) &&
36 StateValuesAreEqual(offset_y_, other.offset_y_);
39 bool PageScrollState::operator!=(const PageScrollState& other) const {
40 return !(*this == other);
43 PageZoomState::PageZoomState()
44 : minimum_zoom_scale_(NAN), maximum_zoom_scale_(NAN), zoom_scale_(NAN) {
47 PageZoomState::PageZoomState(double minimum_zoom_scale,
48 double maximum_zoom_scale,
50 : minimum_zoom_scale_(minimum_zoom_scale),
51 maximum_zoom_scale_(maximum_zoom_scale),
52 zoom_scale_(zoom_scale) {
55 PageZoomState::~PageZoomState() {
58 bool PageZoomState::IsValid() const {
59 return IsLegacyFormat() ||
60 (!std::isnan(minimum_zoom_scale_) &&
61 !std::isnan(maximum_zoom_scale_) && !std::isnan(zoom_scale_) &&
62 zoom_scale_ >= minimum_zoom_scale_ &&
63 zoom_scale_ <= maximum_zoom_scale_);
66 bool PageZoomState::IsLegacyFormat() const {
67 return std::isnan(minimum_zoom_scale_) && std::isnan(maximum_zoom_scale_) &&
71 bool PageZoomState::operator==(const PageZoomState& other) const {
72 return StateValuesAreEqual(minimum_zoom_scale_, other.minimum_zoom_scale_) &&
73 StateValuesAreEqual(maximum_zoom_scale_, other.maximum_zoom_scale_) &&
74 StateValuesAreEqual(zoom_scale_, other.zoom_scale_);
77 bool PageZoomState::operator!=(const PageZoomState& other) const {
78 return !(*this == other);
81 PageDisplayState::PageDisplayState() {
84 PageDisplayState::PageDisplayState(const PageScrollState& scroll_state,
85 const PageZoomState& zoom_state)
86 : scroll_state_(scroll_state), zoom_state_(zoom_state) {
89 PageDisplayState::PageDisplayState(double offset_x,
91 double minimum_zoom_scale,
92 double maximum_zoom_scale,
94 : scroll_state_(offset_x, offset_y),
95 zoom_state_(minimum_zoom_scale, maximum_zoom_scale, zoom_scale) {
98 PageDisplayState::~PageDisplayState() {
101 bool PageDisplayState::IsValid() const {
102 return scroll_state_.IsValid() && zoom_state_.IsValid();
105 bool PageDisplayState::operator==(const PageDisplayState& other) const {
106 return scroll_state_ == other.scroll_state_ &&
107 zoom_state_ == other.zoom_state_;
110 bool PageDisplayState::operator!=(const PageDisplayState& other) const {
111 return !(*this == other);