Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: ios/web/public/web_state/page_scroll_state.mm

Issue 1028603004: Upstream ios/web/navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ios-testing
Patch Set: Rebase and resync Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/public/web_state/page_scroll_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ios/web/public/web_state/page_scroll_state.h"
6
7 #include <cmath>
8
9 namespace web {
10
11 namespace {
12 // Returns true if:
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;
17 }
18 } // namespace
19
20 PageScrollState::PageScrollState()
21 : scroll_offset_x_(NAN),
22 scroll_offset_y_(NAN),
23 minimum_zoom_scale_(NAN),
24 maximum_zoom_scale_(NAN),
25 zoom_scale_(NAN) {
26 }
27
28 PageScrollState::PageScrollState(double scroll_offset_x,
29 double scroll_offset_y,
30 double minimum_zoom_scale,
31 double maximum_zoom_scale,
32 double 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) {
38 }
39
40 PageScrollState::~PageScrollState() {
41 }
42
43 bool PageScrollState::IsValid() const {
44 return IsScrollOffsetValid() && IsZoomScaleValid();
45 }
46
47 bool PageScrollState::IsScrollOffsetValid() const {
48 return !std::isnan(scroll_offset_x_) && !std::isnan(scroll_offset_y_);
49 }
50
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_);
57 }
58
59 bool PageScrollState::IsZoomScaleLegacyFormat() const {
60 return std::isnan(minimum_zoom_scale_) && std::isnan(maximum_zoom_scale_) &&
61 zoom_scale_ > 0.0;
62 }
63
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_);
70 }
71
72 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/public/web_state/page_scroll_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698