summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkkhorimoto <kkhorimoto@chromium.org>2015-06-12 14:14:24 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-12 21:15:01 +0000
commit460d348c1b863cb1ff2fd7436a7e1291fcfb21f9 (patch)
treea9ddd646e65ec8a33e260fca5c73b9b88785bf53
parentdcabbb797b68f8b79d446bbe82acc5b7daade5de (diff)
downloadchromium_src-460d348c1b863cb1ff2fd7436a7e1291fcfb21f9.zip
chromium_src-460d348c1b863cb1ff2fd7436a7e1291fcfb21f9.tar.gz
chromium_src-460d348c1b863cb1ff2fd7436a7e1291fcfb21f9.tar.bz2
Renamed PageScrollState to PageDisplayState.
This CL separates out the PageScrollState and PageZoomState as separate objects owned by a top-level PageState. BUG=none Review URL: https://codereview.chromium.org/1175133003 Cr-Commit-Position: refs/heads/master@{#334237}
-rw-r--r--ios/web/ios_web.gyp4
-rw-r--r--ios/web/navigation/crw_session_entry.mm85
-rw-r--r--ios/web/navigation/crw_session_entry_unittest.mm40
-rw-r--r--ios/web/navigation/navigation_item_impl.h6
-rw-r--r--ios/web/navigation/navigation_item_impl.mm12
-rw-r--r--ios/web/public/navigation_item.h6
-rw-r--r--ios/web/public/web_state/page_display_state.h136
-rw-r--r--ios/web/public/web_state/page_display_state.mm114
-rw-r--r--ios/web/public/web_state/page_scroll_state.h81
-rw-r--r--ios/web/public/web_state/page_scroll_state.mm76
-rw-r--r--ios/web/web_state/ui/crw_ui_web_view_web_controller.mm12
-rw-r--r--ios/web/web_state/ui/crw_web_controller+protected.h8
-rw-r--r--ios/web/web_state/ui/crw_web_controller.mm112
-rw-r--r--ios/web/web_state/ui/crw_web_controller_unittest.mm58
-rw-r--r--ios/web/web_state/ui/crw_wk_web_view_web_controller.mm10
15 files changed, 434 insertions, 326 deletions
diff --git a/ios/web/ios_web.gyp b/ios/web/ios_web.gyp
index 7bc0242..5b0f50b 100644
--- a/ios/web/ios_web.gyp
+++ b/ios/web/ios_web.gyp
@@ -182,8 +182,8 @@
'public/web_state/js/crw_js_injection_evaluator.h',
'public/web_state/js/crw_js_injection_manager.h',
'public/web_state/js/crw_js_injection_receiver.h',
- 'public/web_state/page_scroll_state.h',
- 'public/web_state/page_scroll_state.mm',
+ 'public/web_state/page_display_state.h',
+ 'public/web_state/page_display_state.mm',
'public/web_state/ui/crw_native_content.h',
'public/web_state/ui/crw_native_content_provider.h',
'public/web_state/url_verification_constants.h',
diff --git a/ios/web/navigation/crw_session_entry.mm b/ios/web/navigation/crw_session_entry.mm
index 31d695c..f47448e 100644
--- a/ios/web/navigation/crw_session_entry.mm
+++ b/ios/web/navigation/crw_session_entry.mm
@@ -11,7 +11,7 @@
#include "ios/web/navigation/navigation_item_impl.h"
#include "ios/web/navigation/nscoder_util.h"
#include "ios/web/public/navigation_item.h"
-#include "ios/web/public/web_state/page_scroll_state.h"
+#include "ios/web/public/web_state/page_display_state.h"
#import "net/base/mac/url_conversions.h"
namespace web {
@@ -53,13 +53,15 @@ NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent";
// Redefine originalUrl to be read-write.
@property(nonatomic, readwrite) const GURL& originalUrl;
-// Converts a serialized NSDictionary to a web::PageScrollState.
-+ (web::PageScrollState)scrollStateFromDictionary:(NSDictionary*)dictionary;
-// Serializes a web::PageScrollState to an NSDictionary.
-+ (NSDictionary*)dictionaryFromScrollState:
- (const web::PageScrollState&)scrollState;
-// Returns a readable description of |scrollState|.
-+ (NSString*)scrollStateDescription:(const web::PageScrollState&)scrollState;
+// Converts a serialized NSDictionary to a web::PageDisplayState.
++ (web::PageDisplayState)pageDisplayStateFromDictionary:
+ (NSDictionary*)dictionary;
+// Serializes a web::PageDisplayState to an NSDictionary.
++ (NSDictionary*)dictionaryFromPageDisplayState:
+ (const web::PageDisplayState&)displayState;
+// Returns a readable description of |displayState|.
++ (NSString*)descriptionForPageDisplayState:
+ (const web::PageDisplayState&)displayState;
@end
@implementation CRWSessionEntry
@@ -123,8 +125,8 @@ NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent";
_navigationItem->SetPageID(-1);
_navigationItem->SetTitle(base::SysNSStringToUTF16(title));
_navigationItem->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
- _navigationItem->SetPageScrollState([[self class]
- scrollStateFromDictionary:
+ _navigationItem->SetPageDisplayState([[self class]
+ pageDisplayStateFromDictionary:
[aDecoder
decodeObjectForKey:web::kSessionEntryPageScrollStateKey]]);
_navigationItem->SetShouldSkipResubmitDataConfirmation([aDecoder
@@ -153,8 +155,8 @@ NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent";
[aCoder encodeObject:base::SysUTF16ToNSString(_navigationItem->GetTitle())
forKey:web::kSessionEntryTitleKey];
- [aCoder encodeObject:[[self class] dictionaryFromScrollState:
- _navigationItem->GetPageScrollState()]
+ [aCoder encodeObject:[[self class] dictionaryFromPageDisplayState:
+ _navigationItem->GetPageDisplayState()]
forKey:web::kSessionEntryPageScrollStateKey];
[aCoder encodeBool:_navigationItem->ShouldSkipResubmitDataConfirmation()
forKey:web::kSessionEntrySkipResubmitConfirmationKey];
@@ -180,14 +182,14 @@ NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent";
- (NSString*)description {
return [NSString
stringWithFormat:
- @"url:%@ originalurl:%@ title:%@ transition:%d scrollState:%@ "
+ @"url:%@ originalurl:%@ title:%@ transition:%d displayState:%@ "
@"desktopUA:%d",
base::SysUTF8ToNSString(_navigationItem->GetURL().spec()),
base::SysUTF8ToNSString(self.originalUrl.spec()),
base::SysUTF16ToNSString(_navigationItem->GetTitle()),
_navigationItem->GetTransitionType(),
- [[self class]
- scrollStateDescription:_navigationItem->GetPageScrollState()],
+ [[self class] descriptionForPageDisplayState:
+ _navigationItem->GetPageDisplayState()],
_navigationItem->IsOverridingUserAgent()];
}
@@ -201,43 +203,52 @@ NSString* const kSessionEntryUseDesktopUserAgentKey = @"useDesktopUserAgent";
#pragma mark - Serialization helpers
-+ (web::PageScrollState)scrollStateFromDictionary:(NSDictionary*)dictionary {
- web::PageScrollState scrollState;
++ (web::PageDisplayState)pageDisplayStateFromDictionary:
+ (NSDictionary*)dictionary {
NSNumber* serializedValue = nil;
+ web::PageScrollState scrollState;
if ((serializedValue = dictionary[web::kSessionEntryScrollOffsetXKey]))
- scrollState.set_scroll_offset_x([serializedValue doubleValue]);
+ scrollState.set_offset_x([serializedValue doubleValue]);
if ((serializedValue = dictionary[web::kSessionEntryScrollOffsetYKey]))
- scrollState.set_scroll_offset_y([serializedValue doubleValue]);
+ scrollState.set_offset_y([serializedValue doubleValue]);
+ web::PageZoomState zoomState;
if ((serializedValue = dictionary[web::kSessionEntryMinimumZoomScaleKey]))
- scrollState.set_minimum_zoom_scale([serializedValue doubleValue]);
+ zoomState.set_minimum_zoom_scale([serializedValue doubleValue]);
if ((serializedValue = dictionary[web::kSessionEntryMaximumZoomScaleKey]))
- scrollState.set_maximum_zoom_scale([serializedValue doubleValue]);
+ zoomState.set_maximum_zoom_scale([serializedValue doubleValue]);
if ((serializedValue = dictionary[web::kSessionEntryZoomScaleKey]))
- scrollState.set_zoom_scale([serializedValue doubleValue]);
- return scrollState;
+ zoomState.set_zoom_scale([serializedValue doubleValue]);
+ return web::PageDisplayState(scrollState, zoomState);
}
-+ (NSDictionary*)dictionaryFromScrollState:
- (const web::PageScrollState&)scrollState {
++ (NSDictionary*)dictionaryFromPageDisplayState:
+ (const web::PageDisplayState&)displayState {
return @{
- web::kSessionEntryScrollOffsetXKey : @(scrollState.scroll_offset_x()),
- web::kSessionEntryScrollOffsetYKey : @(scrollState.scroll_offset_y()),
- web::kSessionEntryMinimumZoomScaleKey : @(scrollState.minimum_zoom_scale()),
- web::kSessionEntryMaximumZoomScaleKey : @(scrollState.maximum_zoom_scale()),
- web::kSessionEntryZoomScaleKey : @(scrollState.zoom_scale()),
+ web::kSessionEntryScrollOffsetXKey :
+ @(displayState.scroll_state().offset_x()),
+ web::kSessionEntryScrollOffsetYKey :
+ @(displayState.scroll_state().offset_y()),
+ web::kSessionEntryMinimumZoomScaleKey :
+ @(displayState.zoom_state().minimum_zoom_scale()),
+ web::kSessionEntryMaximumZoomScaleKey :
+ @(displayState.zoom_state().maximum_zoom_scale()),
+ web::kSessionEntryZoomScaleKey :
+ @(displayState.zoom_state().zoom_scale())
};
}
-+ (NSString*)scrollStateDescription:(const web::PageScrollState&)scrollState {
++ (NSString*)descriptionForPageDisplayState:
+ (const web::PageDisplayState&)displayState {
NSString* const kPageScrollStateDescriptionFormat =
@"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), "
@"zoomScale:%0.2f }";
- return [NSString stringWithFormat:kPageScrollStateDescriptionFormat,
- scrollState.scroll_offset_x(),
- scrollState.scroll_offset_y(),
- scrollState.minimum_zoom_scale(),
- scrollState.maximum_zoom_scale(),
- scrollState.zoom_scale()];
+ return
+ [NSString stringWithFormat:kPageScrollStateDescriptionFormat,
+ displayState.scroll_state().offset_x(),
+ displayState.scroll_state().offset_y(),
+ displayState.zoom_state().minimum_zoom_scale(),
+ displayState.zoom_state().maximum_zoom_scale(),
+ displayState.zoom_state().zoom_scale()];
}
@end
diff --git a/ios/web/navigation/crw_session_entry_unittest.mm b/ios/web/navigation/crw_session_entry_unittest.mm
index e660af3..8ffacf7 100644
--- a/ios/web/navigation/crw_session_entry_unittest.mm
+++ b/ios/web/navigation/crw_session_entry_unittest.mm
@@ -19,9 +19,9 @@
#include "ui/base/page_transition_types.h"
@interface CRWSessionEntry (ExposedForTesting)
-+ (web::PageScrollState)scrollStateFromDictionary:(NSDictionary*)dictionary;
-+ (NSDictionary*)dictionaryFromScrollState:
- (const web::PageScrollState&)scrollState;
++ (web::PageScrollState)pageStateFromDictionary:(NSDictionary*)dictionary;
++ (NSDictionary*)dictionaryFromPageDisplayState:
+ (const web::PageDisplayState&)displayState;
@end
class CRWSessionEntryTest : public PlatformTest {
@@ -78,7 +78,7 @@ void CRWSessionEntryTest::expectEqualSessionEntries(
EXPECT_EQ(navItem1->GetReferrer().url, navItem2->GetReferrer().url);
EXPECT_EQ(navItem1->GetTimestamp(), navItem2->GetTimestamp());
EXPECT_EQ(navItem1->GetTitle(), navItem2->GetTitle());
- EXPECT_EQ(navItem1->GetPageScrollState(), navItem2->GetPageScrollState());
+ EXPECT_EQ(navItem1->GetPageDisplayState(), navItem2->GetPageDisplayState());
EXPECT_EQ(navItem1->ShouldSkipResubmitDataConfirmation(),
navItem2->ShouldSkipResubmitDataConfirmation());
EXPECT_EQ(navItem1->IsOverridingUserAgent(),
@@ -94,7 +94,7 @@ TEST_F(CRWSessionEntryTest, Description) {
[sessionEntry_ navigationItem]->SetTitle(base::SysNSStringToUTF16(@"Title"));
EXPECT_NSEQ([sessionEntry_ description],
@"url:http://init.test/ originalurl:http://init.test/ "
- @"title:Title transition:2 scrollState:{ scrollOffset:(nan, "
+ @"title:Title transition:2 displayState:{ scrollOffset:(nan, "
@"nan), zoomScaleRange:(nan, nan), zoomScale:nan } desktopUA:0");
}
@@ -128,11 +128,11 @@ TEST_F(CRWSessionEntryTest, InitWithCoder) {
decodeObjectForKey:web::kSessionEntryReferrerURLDeprecatedKey];
[[[decoder expect] andReturn:title]
decodeObjectForKey:web::kSessionEntryTitleKey];
- const web::PageScrollState& scrollState =
- [sessionEntry_ navigationItem]->GetPageScrollState();
- NSDictionary* serializedScrollState =
- [CRWSessionEntry dictionaryFromScrollState:scrollState];
- [[[decoder expect] andReturn:serializedScrollState]
+ const web::PageDisplayState& pageState =
+ [sessionEntry_ navigationItem]->GetPageDisplayState();
+ NSDictionary* serializedPageDisplayState =
+ [CRWSessionEntry dictionaryFromPageDisplayState:pageState];
+ [[[decoder expect] andReturn:serializedPageDisplayState]
decodeObjectForKey:web::kSessionEntryPageScrollStateKey];
BOOL useDesktopUserAgent =
[sessionEntry_ navigationItem]->IsOverridingUserAgent();
@@ -199,11 +199,11 @@ TEST_F(CRWSessionEntryTest, InitWithCoderNewStyle) {
decodeInt64ForKey:web::kSessionEntryTimestampKey];
[[[decoder expect] andReturn:title]
decodeObjectForKey:web::kSessionEntryTitleKey];
- const web::PageScrollState& scrollState =
- [sessionEntry_ navigationItem]->GetPageScrollState();
- NSDictionary* serializedScrollState =
- [CRWSessionEntry dictionaryFromScrollState:scrollState];
- [[[decoder expect] andReturn:serializedScrollState]
+ const web::PageDisplayState& pageState =
+ [sessionEntry_ navigationItem]->GetPageDisplayState();
+ NSDictionary* serializedPageDisplayState =
+ [CRWSessionEntry dictionaryFromPageDisplayState:pageState];
+ [[[decoder expect] andReturn:serializedPageDisplayState]
decodeObjectForKey:web::kSessionEntryPageScrollStateKey];
BOOL useDesktopUserAgent =
[sessionEntry_ navigationItem]->IsOverridingUserAgent();
@@ -268,11 +268,11 @@ TEST_F(CRWSessionEntryTest, EncodeWithCoder) {
[[coder expect] encodeInt64:item->GetTimestamp().ToInternalValue()
forKey:web::kSessionEntryTimestampKey];
[[coder expect] encodeObject:title forKey:web::kSessionEntryTitleKey];
- const web::PageScrollState& scrollState =
- [sessionEntry_ navigationItem]->GetPageScrollState();
- NSDictionary* serializedScrollState =
- [CRWSessionEntry dictionaryFromScrollState:scrollState];
- [[coder expect] encodeObject:serializedScrollState
+ const web::PageDisplayState& pageState =
+ [sessionEntry_ navigationItem]->GetPageDisplayState();
+ NSDictionary* serializedPageDisplayState =
+ [CRWSessionEntry dictionaryFromPageDisplayState:pageState];
+ [[coder expect] encodeObject:serializedPageDisplayState
forKey:web::kSessionEntryPageScrollStateKey];
BOOL useDesktopUserAgent =
[sessionEntry_ navigationItem]->IsOverridingUserAgent();
diff --git a/ios/web/navigation/navigation_item_impl.h b/ios/web/navigation/navigation_item_impl.h
index f7bc289..6430e40 100644
--- a/ios/web/navigation/navigation_item_impl.h
+++ b/ios/web/navigation/navigation_item_impl.h
@@ -52,8 +52,8 @@ class NavigationItemImpl : public web::NavigationItem {
const base::string16& GetTitle() const override;
void SetPageID(int page_id) override;
int32 GetPageID() const override;
- void SetPageScrollState(const PageScrollState& scroll_state) override;
- const PageScrollState& GetPageScrollState() const override;
+ void SetPageDisplayState(const PageDisplayState& display_state) override;
+ const PageDisplayState& GetPageDisplayState() const override;
const base::string16& GetTitleForDisplay(
const std::string& languages) const override;
void SetTransitionType(ui::PageTransition transition_type) override;
@@ -117,7 +117,7 @@ class NavigationItemImpl : public web::NavigationItem {
GURL virtual_url_;
base::string16 title_;
int32 page_id_;
- PageScrollState page_scroll_state_;
+ PageDisplayState page_display_state_;
ui::PageTransition transition_type_;
FaviconStatus favicon_;
SSLStatus ssl_;
diff --git a/ios/web/navigation/navigation_item_impl.mm b/ios/web/navigation/navigation_item_impl.mm
index 5609aab..367665c 100644
--- a/ios/web/navigation/navigation_item_impl.mm
+++ b/ios/web/navigation/navigation_item_impl.mm
@@ -50,7 +50,7 @@ NavigationItemImpl::NavigationItemImpl(const NavigationItemImpl& item)
virtual_url_(item.virtual_url_),
title_(item.title_),
page_id_(item.page_id_),
- page_scroll_state_(item.page_scroll_state_),
+ page_display_state_(item.page_display_state_),
transition_type_(item.transition_type_),
favicon_(item.favicon_),
ssl_(item.ssl_),
@@ -124,13 +124,13 @@ int32 NavigationItemImpl::GetPageID() const {
return page_id_;
}
-void NavigationItemImpl::SetPageScrollState(
- const web::PageScrollState& scroll_state) {
- page_scroll_state_ = scroll_state;
+void NavigationItemImpl::SetPageDisplayState(
+ const web::PageDisplayState& display_state) {
+ page_display_state_ = display_state;
}
-const PageScrollState& NavigationItemImpl::GetPageScrollState() const {
- return page_scroll_state_;
+const PageDisplayState& NavigationItemImpl::GetPageDisplayState() const {
+ return page_display_state_;
}
const base::string16& NavigationItemImpl::GetTitleForDisplay(
diff --git a/ios/web/public/navigation_item.h b/ios/web/public/navigation_item.h
index 6148e6c0..c4f661b 100644
--- a/ios/web/public/navigation_item.h
+++ b/ios/web/public/navigation_item.h
@@ -8,7 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
-#include "ios/web/public/web_state/page_scroll_state.h"
+#include "ios/web/public/web_state/page_display_state.h"
#include "ui/base/page_transition_types.h"
class GURL;
@@ -76,8 +76,8 @@ class NavigationItem {
virtual int32 GetPageID() const = 0;
// Stores the NavigationItem's last recorded scroll offset and zoom scale.
- virtual void SetPageScrollState(const PageScrollState& scroll_state) = 0;
- virtual const PageScrollState& GetPageScrollState() const = 0;
+ virtual void SetPageDisplayState(const PageDisplayState& page_state) = 0;
+ virtual const PageDisplayState& GetPageDisplayState() const = 0;
// Page-related helpers ------------------------------------------------------
diff --git a/ios/web/public/web_state/page_display_state.h b/ios/web/public/web_state/page_display_state.h
new file mode 100644
index 0000000..7098e2f
--- /dev/null
+++ b/ios/web/public/web_state/page_display_state.h
@@ -0,0 +1,136 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_
+#define IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_
+
+namespace web {
+
+// Class used to represent the scrolling offset of a webview.
+class PageScrollState {
+ public:
+ // Default constructor. Initializes scroll offsets to NAN.
+ PageScrollState();
+ // Constructor with initial values.
+ PageScrollState(double offset_x, double offset_y);
+ ~PageScrollState();
+
+ // The scroll offset is valid if its x and y values are both non-NAN.
+ bool IsValid() const;
+
+ // Accessors for scroll offsets and zoom scale.
+ double offset_x() const { return offset_x_; }
+ void set_offset_x(double offset_x) { offset_x_ = offset_x; }
+ double offset_y() const { return offset_y_; }
+ void set_offset_y(double offset_y) { offset_y_ = offset_y; }
+
+ // Comparator operators.
+ bool operator==(const PageScrollState& other) const;
+ bool operator!=(const PageScrollState& other) const;
+
+ private:
+ // The x value of the page's UIScrollView contentOffset.
+ double offset_x_;
+ // The y value of the page's UIScrollView contentOffset.
+ double offset_y_;
+};
+
+// Class used to represent the scrolling offset and the zoom scale of a webview.
+class PageZoomState {
+ public:
+ // Default constructor. Initializes scroll offsets and zoom scales to NAN.
+ PageZoomState();
+ // Constructor with initial values.
+ PageZoomState(double minimum_zoom_scale,
+ double maximum_zoom_scale,
+ double zoom_scale);
+ ~PageZoomState();
+
+ // Non-legacy zoom scales are valid if all three values are non-NAN and the
+ // zoom scale is within the minimum and maximum scales. Legacy-format
+ // PageScrollStates are considered valid if the minimum and maximum scales
+ // are NAN and the zoom scale is greater than zero.
+ bool IsValid() const;
+
+ // PageScrollStates restored from the legacy serialization format make
+ // assumptions about the web view's implementation of zooming, and contain a
+ // non-NAN zoom scale and a NAN minimum and maximum scale. Legacy zoom scales
+ // can only be applied to CRWUIWebViewWebControllers.
+ bool IsLegacyFormat() const;
+
+ // Returns the allowed zoom scale range for this scroll state.
+ double GetMinMaxZoomDifference() const {
+ return maximum_zoom_scale_ - minimum_zoom_scale_;
+ }
+
+ // Accessors.
+ double minimum_zoom_scale() const { return minimum_zoom_scale_; }
+ void set_minimum_zoom_scale(double minimum_zoom_scale) {
+ minimum_zoom_scale_ = minimum_zoom_scale;
+ }
+ double maximum_zoom_scale() const { return maximum_zoom_scale_; }
+ void set_maximum_zoom_scale(double maximum_zoom_scale) {
+ maximum_zoom_scale_ = maximum_zoom_scale;
+ }
+ double zoom_scale() const { return zoom_scale_; }
+ void set_zoom_scale(double zoom_scale) { zoom_scale_ = zoom_scale; }
+
+ // Comparator operators.
+ bool operator==(const PageZoomState& other) const;
+ bool operator!=(const PageZoomState& other) const;
+
+ private:
+ // The minimumZoomScale value of the page's UIScrollView.
+ double minimum_zoom_scale_;
+ // The maximumZoomScale value of the page's UIScrollView.
+ double maximum_zoom_scale_;
+ // The zoomScale value of the page's UIScrollView.
+ double zoom_scale_;
+};
+
+// Class used to represent the scroll offset and zoom scale of a webview.
+class PageDisplayState {
+ public:
+ // Default constructor. Initializes scroll offsets and zoom scales to NAN.
+ PageDisplayState();
+ // Constructor with initial values.
+ PageDisplayState(const PageScrollState& scroll_state,
+ const PageZoomState& zoom_state);
+ PageDisplayState(double offset_x,
+ double offset_y,
+ double minimum_zoom_scale,
+ double maximum_zoom_scale,
+ double zoom_scale);
+ ~PageDisplayState();
+
+ // PageScrollStates cannot be applied until the scroll offset and zoom scale
+ // are both valid.
+ bool IsValid() const;
+
+ // Accessors.
+ const PageScrollState& scroll_state() const { return scroll_state_; }
+ PageScrollState& scroll_state() { return scroll_state_; }
+ void set_scroll_state(const PageScrollState& scroll_state) {
+ scroll_state_ = scroll_state;
+ }
+ const PageZoomState& zoom_state() const { return zoom_state_; }
+ PageZoomState& zoom_state() { return zoom_state_; }
+ void set_zoom_state(const PageZoomState& zoom_state) {
+ zoom_state_ = zoom_state;
+ }
+
+ // Comparator operators.
+ bool operator==(const PageDisplayState& other) const;
+ bool operator!=(const PageDisplayState& other) const;
+
+ private:
+ // The scroll state for the page's UIScrollView.
+ PageScrollState scroll_state_;
+ // The zoom state for the page's UIScrollView.
+ PageZoomState zoom_state_;
+};
+
+} // namespace web
+
+#endif // IOS_WEB_PUBLIC_WEB_STATE_PAGE_DISPLAY_STATE_H_
diff --git a/ios/web/public/web_state/page_display_state.mm b/ios/web/public/web_state/page_display_state.mm
new file mode 100644
index 0000000..6837ecb
--- /dev/null
+++ b/ios/web/public/web_state/page_display_state.mm
@@ -0,0 +1,114 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/public/web_state/page_display_state.h"
+
+#include <cmath>
+
+namespace web {
+
+namespace {
+// Returns true if:
+// - both |value1| and |value2| are NAN, or
+// - |value1| and |value2| are equal non-NAN values.
+inline bool StateValuesAreEqual(double value1, double value2) {
+ return std::isnan(value1) ? std::isnan(value2) : value1 == value2;
+}
+} // namespace
+
+PageScrollState::PageScrollState() : offset_x_(NAN), offset_y_(NAN) {
+}
+
+PageScrollState::PageScrollState(double offset_x, double offset_y)
+ : offset_x_(offset_x), offset_y_(offset_y) {
+}
+
+PageScrollState::~PageScrollState() {
+}
+
+bool PageScrollState::IsValid() const {
+ return !std::isnan(offset_x_) && !std::isnan(offset_y_);
+}
+
+bool PageScrollState::operator==(const PageScrollState& other) const {
+ return StateValuesAreEqual(offset_x_, other.offset_x_) &&
+ StateValuesAreEqual(offset_y_, other.offset_y_);
+}
+
+bool PageScrollState::operator!=(const PageScrollState& other) const {
+ return !(*this == other);
+}
+
+PageZoomState::PageZoomState()
+ : minimum_zoom_scale_(NAN), maximum_zoom_scale_(NAN), zoom_scale_(NAN) {
+}
+
+PageZoomState::PageZoomState(double minimum_zoom_scale,
+ double maximum_zoom_scale,
+ double zoom_scale)
+ : minimum_zoom_scale_(minimum_zoom_scale),
+ maximum_zoom_scale_(maximum_zoom_scale),
+ zoom_scale_(zoom_scale) {
+}
+
+PageZoomState::~PageZoomState() {
+}
+
+bool PageZoomState::IsValid() const {
+ return IsLegacyFormat() ||
+ (!std::isnan(minimum_zoom_scale_) &&
+ !std::isnan(maximum_zoom_scale_) && !std::isnan(zoom_scale_) &&
+ zoom_scale_ >= minimum_zoom_scale_ &&
+ zoom_scale_ <= maximum_zoom_scale_);
+}
+
+bool PageZoomState::IsLegacyFormat() const {
+ return std::isnan(minimum_zoom_scale_) && std::isnan(maximum_zoom_scale_) &&
+ zoom_scale_ > 0.0;
+}
+
+bool PageZoomState::operator==(const PageZoomState& other) const {
+ return StateValuesAreEqual(minimum_zoom_scale_, other.minimum_zoom_scale_) &&
+ StateValuesAreEqual(maximum_zoom_scale_, other.maximum_zoom_scale_) &&
+ StateValuesAreEqual(zoom_scale_, other.zoom_scale_);
+}
+
+bool PageZoomState::operator!=(const PageZoomState& other) const {
+ return !(*this == other);
+}
+
+PageDisplayState::PageDisplayState() {
+}
+
+PageDisplayState::PageDisplayState(const PageScrollState& scroll_state,
+ const PageZoomState& zoom_state)
+ : scroll_state_(scroll_state), zoom_state_(zoom_state) {
+}
+
+PageDisplayState::PageDisplayState(double offset_x,
+ double offset_y,
+ double minimum_zoom_scale,
+ double maximum_zoom_scale,
+ double zoom_scale)
+ : scroll_state_(offset_x, offset_y),
+ zoom_state_(minimum_zoom_scale, maximum_zoom_scale, zoom_scale) {
+}
+
+PageDisplayState::~PageDisplayState() {
+}
+
+bool PageDisplayState::IsValid() const {
+ return scroll_state_.IsValid() && zoom_state_.IsValid();
+}
+
+bool PageDisplayState::operator==(const PageDisplayState& other) const {
+ return scroll_state_ == other.scroll_state_ &&
+ zoom_state_ == other.zoom_state_;
+}
+
+bool PageDisplayState::operator!=(const PageDisplayState& other) const {
+ return !(*this == other);
+}
+
+} // namespace web
diff --git a/ios/web/public/web_state/page_scroll_state.h b/ios/web/public/web_state/page_scroll_state.h
deleted file mode 100644
index 7fceb2c..0000000
--- a/ios/web/public/web_state/page_scroll_state.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IOS_WEB_PUBLIC_WEB_STATE_PAGE_SCROLL_STATE_H_
-#define IOS_WEB_PUBLIC_WEB_STATE_PAGE_SCROLL_STATE_H_
-
-namespace web {
-
-// Class used to represent the scrolling offset and the zoom scale of a webview.
-class PageScrollState {
- public:
- // Default constructor. Initializes scroll offsets and zoom scales to NAN.
- PageScrollState();
- // Constructor with initial values.
- PageScrollState(double scroll_offset_x,
- double scroll_offset_y,
- double minimum_zoom_scale,
- double maximum_zoom_scale,
- double zoom_scale);
- ~PageScrollState();
-
- // PageScrollStates cannot be applied until the scroll offset and zoom scale
- // are both valid.
- bool IsValid() const;
-
- // The scroll offset is valid if its x and y values are both non-NAN.
- bool IsScrollOffsetValid() const;
-
- // Non-legacy zoom scales are valid if all three values are non-NAN and the
- // zoom scale is within the minimum and maximum scales. Legacy-format
- // PageScrollStates are considered valid if the minimum and maximum scales
- // are NAN and the zoom scale is greater than zero.
- bool IsZoomScaleValid() const;
-
- // PageScrollStates restored from the legacy serialization format make
- // assumptions about the web view's implementation of zooming, and contain a
- // non-NAN zoom scale and a NAN minimum and maximum scale. Legacy zoom scales
- // can only be applied to CRWUIWebViewWebControllers.
- bool IsZoomScaleLegacyFormat() const;
-
- // Returns the allowed zoom scale range for this scroll state.
- double GetMinMaxZoomDifference() const {
- return maximum_zoom_scale_ - minimum_zoom_scale_;
- }
-
- // Accessors for scroll offsets and zoom scale.
- double scroll_offset_x() const { return scroll_offset_x_; }
- void set_scroll_offset_x(double scroll_offset_x) {
- scroll_offset_x_ = scroll_offset_x;
- }
- double scroll_offset_y() const { return scroll_offset_y_; }
- void set_scroll_offset_y(double scroll_offset_y) {
- scroll_offset_y_ = scroll_offset_y;
- }
- double minimum_zoom_scale() const { return minimum_zoom_scale_; }
- void set_minimum_zoom_scale(double minimum_zoom_scale) {
- minimum_zoom_scale_ = minimum_zoom_scale;
- }
- double maximum_zoom_scale() const { return maximum_zoom_scale_; }
- void set_maximum_zoom_scale(double maximum_zoom_scale) {
- maximum_zoom_scale_ = maximum_zoom_scale;
- }
- double zoom_scale() const { return zoom_scale_; }
- void set_zoom_scale(double zoom_scale) { zoom_scale_ = zoom_scale; }
-
- // Comparator operators.
- bool operator==(const PageScrollState& other) const;
- bool operator!=(const PageScrollState& other) const;
-
- private:
- double scroll_offset_x_;
- double scroll_offset_y_;
- double minimum_zoom_scale_;
- double maximum_zoom_scale_;
- double zoom_scale_;
-};
-
-} // namespace web
-
-#endif // IOS_WEB_PUBLIC_WEB_STATE_PAGE_SCROLL_STATE_H_
diff --git a/ios/web/public/web_state/page_scroll_state.mm b/ios/web/public/web_state/page_scroll_state.mm
deleted file mode 100644
index b77abb7..0000000
--- a/ios/web/public/web_state/page_scroll_state.mm
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ios/web/public/web_state/page_scroll_state.h"
-
-#include <cmath>
-
-namespace web {
-
-namespace {
-// Returns true if:
-// - both |value1| and |value2| are NAN, or
-// - |value1| and |value2| are equal non-NAN values.
-inline bool StateValuesAreEqual(double value1, double value2) {
- return std::isnan(value1) ? std::isnan(value2) : value1 == value2;
-}
-} // namespace
-
-PageScrollState::PageScrollState()
- : scroll_offset_x_(NAN),
- scroll_offset_y_(NAN),
- minimum_zoom_scale_(NAN),
- maximum_zoom_scale_(NAN),
- zoom_scale_(NAN) {
-}
-
-PageScrollState::PageScrollState(double scroll_offset_x,
- double scroll_offset_y,
- double minimum_zoom_scale,
- double maximum_zoom_scale,
- double zoom_scale)
- : scroll_offset_x_(scroll_offset_x),
- scroll_offset_y_(scroll_offset_y),
- minimum_zoom_scale_(minimum_zoom_scale),
- maximum_zoom_scale_(maximum_zoom_scale),
- zoom_scale_(zoom_scale) {
-}
-
-PageScrollState::~PageScrollState() {
-}
-
-bool PageScrollState::IsValid() const {
- return IsScrollOffsetValid() && IsZoomScaleValid();
-}
-
-bool PageScrollState::IsScrollOffsetValid() const {
- return !std::isnan(scroll_offset_x_) && !std::isnan(scroll_offset_y_);
-}
-
-bool PageScrollState::IsZoomScaleValid() const {
- return IsZoomScaleLegacyFormat() ||
- (!std::isnan(minimum_zoom_scale_) &&
- !std::isnan(maximum_zoom_scale_) && !std::isnan(zoom_scale_) &&
- zoom_scale_ >= minimum_zoom_scale_ &&
- zoom_scale_ <= maximum_zoom_scale_);
-}
-
-bool PageScrollState::IsZoomScaleLegacyFormat() const {
- return std::isnan(minimum_zoom_scale_) && std::isnan(maximum_zoom_scale_) &&
- zoom_scale_ > 0.0;
-}
-
-bool PageScrollState::operator==(const PageScrollState& other) const {
- return StateValuesAreEqual(scroll_offset_x_, other.scroll_offset_x_) &&
- StateValuesAreEqual(scroll_offset_y_, other.scroll_offset_y_) &&
- StateValuesAreEqual(minimum_zoom_scale_, other.minimum_zoom_scale_) &&
- StateValuesAreEqual(maximum_zoom_scale_, other.maximum_zoom_scale_) &&
- StateValuesAreEqual(zoom_scale_, other.zoom_scale_);
-}
-
-bool PageScrollState::operator!=(const PageScrollState& other) const {
- return !(*this == other);
-}
-
-} // namespace web
diff --git a/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm b/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
index 7f53f4a..467607f 100644
--- a/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
+++ b/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
@@ -781,8 +781,8 @@ const size_t kMaxMessageQueueSize = 262144;
[super webPageChanged];
}
-- (void)applyWebViewScrollZoomScaleFromScrollState:
- (const web::PageScrollState&)scrollState {
+- (void)applyWebViewScrollZoomScaleFromZoomState:
+ (const web::PageZoomState&)zoomState {
// A UIWebView's scroll view uses zoom scales in a non-standard way. The
// scroll view's |zoomScale| property is always equal to 1.0, and the
// |minimumZoomScale| and |maximumZoomScale| properties are adjusted
@@ -791,11 +791,11 @@ const size_t kMaxMessageQueueSize = 262144;
// 2.0 will update the zoom to twice its initial scale). The maximum-scale or
// minimum-scale meta tags of a page may have changed since the state was
// recorded, so clamp the zoom scale to the current range if necessary.
- DCHECK(scrollState.IsZoomScaleValid());
- CGFloat zoomScale = scrollState.IsZoomScaleLegacyFormat()
- ? scrollState.zoom_scale()
+ DCHECK(zoomState.IsValid());
+ CGFloat zoomScale = zoomState.IsLegacyFormat()
+ ? zoomState.zoom_scale()
: self.webScrollView.minimumZoomScale /
- scrollState.minimum_zoom_scale();
+ zoomState.minimum_zoom_scale();
if (zoomScale < self.webScrollView.minimumZoomScale)
zoomScale = self.webScrollView.minimumZoomScale;
if (zoomScale > self.webScrollView.maximumZoomScale)
diff --git a/ios/web/web_state/ui/crw_web_controller+protected.h b/ios/web/web_state/ui/crw_web_controller+protected.h
index a197e4a..9aab39c4 100644
--- a/ios/web/web_state/ui/crw_web_controller+protected.h
+++ b/ios/web/web_state/ui/crw_web_controller+protected.h
@@ -9,7 +9,7 @@
#include "base/mac/scoped_nsobject.h"
#include "ios/web/public/referrer.h"
-#include "ios/web/public/web_state/page_scroll_state.h"
+#include "ios/web/public/web_state/page_display_state.h"
@class CRWSessionController;
namespace web {
@@ -156,9 +156,9 @@ struct NewWindowInfo {
// |command|. Subclasses may override to handle class-specific messages.
- (SEL)selectorToHandleJavaScriptCommand:(const std::string&)command;
-// Sets zoom scale value for webview scroll view from |scrollState|.
-- (void)applyWebViewScrollZoomScaleFromScrollState:
- (const web::PageScrollState&)scrollState;
+// Sets zoom scale value for webview scroll view from |zoomState|.
+- (void)applyWebViewScrollZoomScaleFromZoomState:
+ (const web::PageZoomState&)zoomState;
// Returns YES if load should be aborted when NSURLCancelledError is
// encountered for |cancelledURL|.
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 16c9151..e332622 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -188,8 +188,8 @@ void CancelAllTouches(UIScrollView* web_scroll_view) {
GURL _URLOnStartLoading;
// Page loading phase.
web::LoadPhase _loadPhase;
- // The web::PageScrollState recorded when the page starts loading.
- web::PageScrollState _scrollStateOnStartLoading;
+ // The web::PageDisplayState recorded when the page starts loading.
+ web::PageDisplayState _displayStateOnStartLoading;
// Whether or not the page has zoomed since the current navigation has been
// committed, either by user interaction or via |-restoreStateFromHistory|.
BOOL _pageHasZoomed;
@@ -261,7 +261,7 @@ void CancelAllTouches(UIScrollView* web_scroll_view) {
// The current page state of the web view. Writing to this property
// asynchronously applies the passed value to the current web view.
-@property(nonatomic, readwrite) web::PageScrollState pageScrollState;
+@property(nonatomic, readwrite) web::PageDisplayState pageDisplayState;
// Resets any state that is associated with a specific document object (e.g.,
// page interaction tracking).
- (void)resetDocumentSpecificState;
@@ -316,12 +316,12 @@ void CancelAllTouches(UIScrollView* web_scroll_view) {
// Called by NSNotificationCenter upon orientation changes.
- (void)orientationDidChange;
// Queries the web view for the user-scalable meta tag and calls
-// |-applyPageScrollState:userScalable:| with the result.
-- (void)applyPageScrollState:(const web::PageScrollState&)scrollState;
+// |-applyPageDisplayState:userScalable:| with the result.
+- (void)applyPageDisplayState:(const web::PageDisplayState&)displayState;
// Restores state of the web view's scroll view from |scrollState|.
// |isUserScalable| represents the value of user-scalable meta tag.
-- (void)applyPageScrollState:(const web::PageScrollState&)scrollState
- userScalable:(BOOL)isUserScalable;
+- (void)applyPageDisplayState:(const web::PageDisplayState&)displayState
+ userScalable:(BOOL)isUserScalable;
// Calls the zoom-preparation UIScrollViewDelegate callbacks on the web view.
// This is called before |-applyWebViewScrollZoomScaleFromScrollState:|.
- (void)prepareToApplyWebViewScrollZoomScale;
@@ -2597,7 +2597,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
- (void)didStartLoadingURL:(const GURL&)url updateHistory:(BOOL)updateHistory {
_loadPhase = web::PAGE_LOADING;
_URLOnStartLoading = url;
- _scrollStateOnStartLoading = self.pageScrollState;
+ _displayStateOnStartLoading = self.pageDisplayState;
_userInteractionRegistered = NO;
_pageHasZoomed = NO;
@@ -3319,45 +3319,47 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
// Check that the url in the web view matches the url in the history entry.
CRWSessionEntry* current = [self currentSessionEntry];
if (current && [current navigationItem]->GetURL() == [self currentURL])
- [current navigationItem]->SetPageScrollState(self.pageScrollState);
+ [current navigationItem]->SetPageDisplayState(self.pageDisplayState);
}
- (void)restoreStateFromHistory {
CRWSessionEntry* current = [self currentSessionEntry];
if ([current navigationItem])
- self.pageScrollState = [current navigationItem]->GetPageScrollState();
+ self.pageDisplayState = [current navigationItem]->GetPageDisplayState();
}
-- (web::PageScrollState)pageScrollState {
- web::PageScrollState scrollState;
+- (web::PageDisplayState)pageDisplayState {
+ web::PageDisplayState displayState;
if (self.webView) {
CGPoint scrollOffset = [self scrollPosition];
- scrollState.set_scroll_offset_x(std::floor(scrollOffset.x));
- scrollState.set_scroll_offset_y(std::floor(scrollOffset.y));
+ displayState.scroll_state().set_offset_x(std::floor(scrollOffset.x));
+ displayState.scroll_state().set_offset_y(std::floor(scrollOffset.y));
UIScrollView* scrollView = self.webScrollView;
- scrollState.set_minimum_zoom_scale(scrollView.minimumZoomScale);
- scrollState.set_maximum_zoom_scale(scrollView.maximumZoomScale);
- scrollState.set_zoom_scale(scrollView.zoomScale);
+ displayState.zoom_state().set_minimum_zoom_scale(
+ scrollView.minimumZoomScale);
+ displayState.zoom_state().set_maximum_zoom_scale(
+ scrollView.maximumZoomScale);
+ displayState.zoom_state().set_zoom_scale(scrollView.zoomScale);
} else {
// TODO(kkhorimoto): Handle native views.
}
- return scrollState;
+ return displayState;
}
-- (void)setPageScrollState:(web::PageScrollState)pageScrollState {
- if (!pageScrollState.IsValid())
+- (void)setPageDisplayState:(web::PageDisplayState)displayState {
+ if (!displayState.IsValid())
return;
if (self.webView) {
// Page state is restored after a page load completes. If the user has
// scrolled or changed the zoom scale while the page is still loading, don't
// restore any state since it will confuse the user.
- web::PageScrollState currentScrollState = self.pageScrollState;
- if (currentScrollState.scroll_offset_x() ==
- _scrollStateOnStartLoading.scroll_offset_x() &&
- currentScrollState.scroll_offset_y() ==
- _scrollStateOnStartLoading.scroll_offset_y() &&
+ web::PageDisplayState currentPageDisplayState = self.pageDisplayState;
+ if (currentPageDisplayState.scroll_state().offset_x() ==
+ _displayStateOnStartLoading.scroll_state().offset_x() &&
+ currentPageDisplayState.scroll_state().offset_y() ==
+ _displayStateOnStartLoading.scroll_state().offset_y() &&
!_pageHasZoomed) {
- [self applyPageScrollState:pageScrollState];
+ [self applyPageDisplayState:displayState];
}
}
}
@@ -3376,48 +3378,50 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
web::NavigationItem* currentItem = self.currentNavItem;
if (!currentItem)
return;
- web::PageScrollState scrollState = currentItem->GetPageScrollState();
- if (!scrollState.IsValid())
+ web::PageDisplayState displayState = currentItem->GetPageDisplayState();
+ if (!displayState.IsValid())
return;
- CGFloat zoomPercentage =
- (scrollState.zoom_scale() - scrollState.minimum_zoom_scale()) /
- scrollState.GetMinMaxZoomDifference();
- scrollState.set_minimum_zoom_scale(self.webScrollView.minimumZoomScale);
- scrollState.set_maximum_zoom_scale(self.webScrollView.maximumZoomScale);
- scrollState.set_zoom_scale(scrollState.minimum_zoom_scale() +
- zoomPercentage *
- scrollState.GetMinMaxZoomDifference());
- currentItem->SetPageScrollState(scrollState);
- [self applyPageScrollState:currentItem->GetPageScrollState()];
-}
-
-- (void)applyPageScrollState:(const web::PageScrollState&)scrollState {
- if (!scrollState.IsValid())
+ CGFloat zoomPercentage = (displayState.zoom_state().zoom_scale() -
+ displayState.zoom_state().minimum_zoom_scale()) /
+ displayState.zoom_state().GetMinMaxZoomDifference();
+ displayState.zoom_state().set_minimum_zoom_scale(
+ self.webScrollView.minimumZoomScale);
+ displayState.zoom_state().set_maximum_zoom_scale(
+ self.webScrollView.maximumZoomScale);
+ displayState.zoom_state().set_zoom_scale(
+ displayState.zoom_state().minimum_zoom_scale() +
+ zoomPercentage * displayState.zoom_state().GetMinMaxZoomDifference());
+ currentItem->SetPageDisplayState(displayState);
+ [self applyPageDisplayState:currentItem->GetPageDisplayState()];
+}
+
+- (void)applyPageDisplayState:(const web::PageDisplayState&)displayState {
+ if (!displayState.IsValid())
return;
base::WeakNSObject<CRWWebController> weakSelf(self);
- web::PageScrollState scrollStateCopy = scrollState;
+ web::PageDisplayState displayStateCopy = displayState;
[self queryUserScalableProperty:^(BOOL isUserScalable) {
base::scoped_nsobject<CRWWebController> strongSelf([weakSelf retain]);
- [strongSelf applyPageScrollState:scrollStateCopy
- userScalable:isUserScalable];
+ [strongSelf applyPageDisplayState:displayStateCopy
+ userScalable:isUserScalable];
}];
}
-- (void)applyPageScrollState:(const web::PageScrollState&)scrollState
- userScalable:(BOOL)isUserScalable {
+- (void)applyPageDisplayState:(const web::PageDisplayState&)displayState
+ userScalable:(BOOL)isUserScalable {
// Early return if |scrollState| doesn't match the current NavigationItem.
// This can sometimes occur in tests, as navigation occurs programmatically
// and |-applyPageScrollState:| is asynchronous.
web::NavigationItem* currentItem = [self currentSessionEntry].navigationItem;
- if (currentItem && currentItem->GetPageScrollState() != scrollState)
+ if (currentItem && currentItem->GetPageDisplayState() != displayState)
return;
- DCHECK(scrollState.IsValid());
+ DCHECK(displayState.IsValid());
if (isUserScalable) {
[self prepareToApplyWebViewScrollZoomScale];
- [self applyWebViewScrollZoomScaleFromScrollState:scrollState];
+ [self applyWebViewScrollZoomScaleFromZoomState:displayState.zoom_state()];
[self finishApplyingWebViewScrollZoomScale];
}
- [self applyWebViewScrollOffsetFromScrollState:scrollState];
+ [self applyWebViewScrollOffsetFromScrollState:displayState.scroll_state()];
}
- (void)prepareToApplyWebViewScrollZoomScale {
@@ -3452,8 +3456,8 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
}
}
-- (void)applyWebViewScrollZoomScaleFromScrollState:
- (const web::PageScrollState&)scrollState {
+- (void)applyWebViewScrollZoomScaleFromZoomState:
+ (const web::PageZoomState&)zoomState {
// Subclasses must implement this method.
NOTREACHED();
}
@@ -3462,7 +3466,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
(const web::PageScrollState&)scrollState {
DCHECK(scrollState.IsValid());
CGPoint scrollOffset =
- CGPointMake(scrollState.scroll_offset_x(), scrollState.scroll_offset_y());
+ CGPointMake(scrollState.offset_x(), scrollState.offset_y());
if (_loadPhase == web::PAGE_LOADED) {
// If the page is loaded, update the scroll immediately.
[self.webScrollView setContentOffset:scrollOffset];
diff --git a/ios/web/web_state/ui/crw_web_controller_unittest.mm b/ios/web/web_state/ui/crw_web_controller_unittest.mm
index 5b65bbc..43c7de4 100644
--- a/ios/web/web_state/ui/crw_web_controller_unittest.mm
+++ b/ios/web/web_state/ui/crw_web_controller_unittest.mm
@@ -880,15 +880,15 @@ WEB_TEST_F(CRWUIWebControllerPageDialogsOpenPolicyTest,
// is needed;
class CRWUIWebControllerPageScrollStateTest : public web::UIWebViewWebTest {
protected:
- // Returns a web::PageScrollState that will scroll a UIWebView to
+ // Returns a web::PageDisplayState that will scroll a UIWebView to
// |scrollOffset| and zoom the content by |relativeZoomScale|.
- inline web::PageScrollState CreateTestScrollState(
+ inline web::PageDisplayState CreateTestPageDisplayState(
CGPoint scroll_offset,
CGFloat relative_zoom_scale,
CGFloat original_minimum_zoom_scale,
CGFloat original_maximum_zoom_scale,
CGFloat original_zoom_scale) const {
- return web::PageScrollState(
+ return web::PageDisplayState(
scroll_offset.x, scroll_offset.y,
original_minimum_zoom_scale / relative_zoom_scale,
original_maximum_zoom_scale / relative_zoom_scale, 1.0);
@@ -899,15 +899,15 @@ class CRWUIWebControllerPageScrollStateTest : public web::UIWebViewWebTest {
// is needed;
class CRWWKWebControllerPageScrollStateTest : public web::WKWebViewWebTest {
protected:
- // Returns a web::PageScrollState that will scroll a WKWebView to
+ // Returns a web::PageDisplayState that will scroll a WKWebView to
// |scrollOffset| and zoom the content by |relativeZoomScale|.
- inline web::PageScrollState CreateTestScrollState(
+ inline web::PageDisplayState CreateTestPageDisplayState(
CGPoint scroll_offset,
CGFloat relative_zoom_scale,
CGFloat original_minimum_zoom_scale,
CGFloat original_maximum_zoom_scale,
CGFloat original_zoom_scale) const {
- return web::PageScrollState(
+ return web::PageDisplayState(
scroll_offset.x, scroll_offset.y, original_minimum_zoom_scale,
original_maximum_zoom_scale,
relative_zoom_scale * original_minimum_zoom_scale);
@@ -917,7 +917,7 @@ class CRWWKWebControllerPageScrollStateTest : public web::WKWebViewWebTest {
// TODO(iOS): Flaky on the bots. crbug/493427
WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
CRWWKWebControllerPageScrollStateTest,
- FLAKY_SetPageStateWithUserScalableDisabled) {
+ FLAKY_SetPageDisplayStateWithUserScalableDisabled) {
#if !TARGET_IPHONE_SIMULATOR
// This test fails flakily on device with WKWebView, so skip it there.
// crbug.com/453530
@@ -936,15 +936,15 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
float originMaximumZoomScale = scrollView.maximumZoomScale;
web::WebState* webState = [this->webController_ webState];
- webState->GetNavigationManager()->GetLastCommittedItem()->SetPageScrollState(
- this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset
- 3.0, // relative zoom scale
- 1.0, // original minimum zoom scale
- 5.0, // original maximum zoom scale
- 1.0)); // original zoom scale
+ webState->GetNavigationManager()->GetLastCommittedItem()->SetPageDisplayState(
+ this->CreateTestPageDisplayState(CGPointMake(1.0, 1.0), // scroll offset
+ 3.0, // relative zoom scale
+ 1.0, // original minimum zoom scale
+ 5.0, // original maximum zoom scale
+ 1.0)); // original zoom scale
[this->webController_ restoreStateFromHistory];
- // setPageState: is async; wait for its completion.
+ // |-restoreStateFromHistory| is async; wait for its completion.
scrollView = [[[this->webController_ view] subviews][0] scrollView];
base::test::ios::WaitUntilCondition(^bool() {
return [scrollView contentOffset].x == 1.0f;
@@ -958,7 +958,7 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
// TODO(iOS): Flaky on the bots. crbug/493427
WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
CRWWKWebControllerPageScrollStateTest,
- FLAKY_SetPageStateWithUserScalableEnabled) {
+ FLAKY_SetPageDisplayStateWithUserScalableEnabled) {
this->LoadHtml(@"<html><head>"
"<meta name='viewport' content="
"'width=device-width,maximum-scale=10,initial-scale=1.0'"
@@ -967,15 +967,15 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
ui::test::uiview_utils::ForceViewRendering([this->webController_ view]);
web::WebState* webState = [this->webController_ webState];
- webState->GetNavigationManager()->GetLastCommittedItem()->SetPageScrollState(
- this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset
- 3.0, // relative zoom scale
- 1.0, // original minimum zoom scale
- 10.0, // original maximum zoom scale
- 1.0)); // original zoom scale
+ webState->GetNavigationManager()->GetLastCommittedItem()->SetPageDisplayState(
+ this->CreateTestPageDisplayState(CGPointMake(1.0, 1.0), // scroll offset
+ 3.0, // relative zoom scale
+ 1.0, // original minimum zoom scale
+ 10.0, // original maximum zoom scale
+ 1.0)); // original zoom scale
[this->webController_ restoreStateFromHistory];
- // setPageState: is async; wait for its completion.
+ // |-restoreStateFromHistory| is async; wait for its completion.
id webView = [[this->webController_ view] subviews][0];
UIScrollView* scrollView = [webView scrollView];
base::test::ios::WaitUntilCondition(^bool() {
@@ -1002,15 +1002,15 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
ASSERT_TRUE(this->webController_.get().atTop);
web::WebState* webState = [this->webController_ webState];
- webState->GetNavigationManager()->GetLastCommittedItem()->SetPageScrollState(
- this->CreateTestScrollState(CGPointMake(0.0, 30.0), // scroll offset
- 5.0, // relative zoom scale
- 1.0, // original minimum zoom scale
- 5.0, // original maximum zoom scale
- 1.0)); // original zoom scale
+ webState->GetNavigationManager()->GetLastCommittedItem()->SetPageDisplayState(
+ this->CreateTestPageDisplayState(CGPointMake(0.0, 30.0), // scroll offset
+ 5.0, // relative zoom scale
+ 1.0, // original minimum zoom scale
+ 5.0, // original maximum zoom scale
+ 1.0)); // original zoom scale
[this->webController_ restoreStateFromHistory];
- // setPageState: is async; wait for its completion.
+ // |-restoreStateFromHistory| is async; wait for its completion.
id webView = [[this->webController_ view] subviews][0];
base::test::ios::WaitUntilCondition(^bool() {
return [[webView scrollView] contentOffset].y == 30.0f;
diff --git a/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm b/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
index b374a60..02eaf64 100644
--- a/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
+++ b/ios/web/web_state/ui/crw_wk_web_view_web_controller.mm
@@ -397,18 +397,18 @@ NSString* const kScriptImmediateName = @"crwebinvokeimmediate";
[self evaluateJavaScript:script stringResultHandler:nil];
}
-- (void)applyWebViewScrollZoomScaleFromScrollState:
- (const web::PageScrollState&)scrollState {
+- (void)applyWebViewScrollZoomScaleFromZoomState:
+ (const web::PageZoomState&)zoomState {
// After rendering a web page, WKWebView keeps the |minimumZoomScale| and
// |maximumZoomScale| properties of its scroll view constant while adjusting
// the |zoomScale| property accordingly. The maximum-scale or minimum-scale
// meta tags of a page may have changed since the state was recorded, so clamp
// the zoom scale to the current range if necessary.
- DCHECK(scrollState.IsZoomScaleValid());
+ DCHECK(zoomState.IsValid());
// Legacy-format scroll states cannot be applied to WKWebViews.
- if (scrollState.IsZoomScaleLegacyFormat())
+ if (zoomState.IsLegacyFormat())
return;
- CGFloat zoomScale = scrollState.zoom_scale();
+ CGFloat zoomScale = zoomState.zoom_scale();
if (zoomScale < self.webScrollView.minimumZoomScale)
zoomScale = self.webScrollView.minimumZoomScale;
if (zoomScale > self.webScrollView.maximumZoomScale)