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_scroll_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()
21 : scroll_offset_x_(NAN),
22 scroll_offset_y_(NAN),
23 minimum_zoom_scale_(NAN),
24 maximum_zoom_scale_(NAN),
28 PageScrollState::PageScrollState(double scroll_offset_x,
29 double scroll_offset_y,
30 double minimum_zoom_scale,
31 double maximum_zoom_scale,
33 : scroll_offset_x_(scroll_offset_x),
34 scroll_offset_y_(scroll_offset_y),
35 minimum_zoom_scale_(minimum_zoom_scale),
36 maximum_zoom_scale_(maximum_zoom_scale),
37 zoom_scale_(zoom_scale) {
40 PageScrollState::~PageScrollState() {
43 bool PageScrollState::IsValid() const {
44 return IsScrollOffsetValid() && IsZoomScaleValid();
47 bool PageScrollState::IsScrollOffsetValid() const {
48 return !std::isnan(scroll_offset_x_) && !std::isnan(scroll_offset_y_);
51 bool PageScrollState::IsZoomScaleValid() const {
52 return IsZoomScaleLegacyFormat() ||
53 (!std::isnan(minimum_zoom_scale_) &&
54 !std::isnan(maximum_zoom_scale_) && !std::isnan(zoom_scale_) &&
55 zoom_scale_ >= minimum_zoom_scale_ &&
56 zoom_scale_ <= maximum_zoom_scale_);
59 bool PageScrollState::IsZoomScaleLegacyFormat() const {
60 return std::isnan(minimum_zoom_scale_) && std::isnan(maximum_zoom_scale_) &&
64 bool PageScrollState::operator==(const PageScrollState& other) const {
65 return StateValuesAreEqual(scroll_offset_x_, other.scroll_offset_x_) &&
66 StateValuesAreEqual(scroll_offset_y_, other.scroll_offset_y_) &&
67 StateValuesAreEqual(minimum_zoom_scale_, other.minimum_zoom_scale_) &&
68 StateValuesAreEqual(maximum_zoom_scale_, other.maximum_zoom_scale_) &&
69 StateValuesAreEqual(zoom_scale_, other.zoom_scale_);