Commit bfc7eb20 authored by bokan's avatar bokan Committed by Commit bot

Don't calculate a shown ratio when top controls height is 0.

This was causing a crash in Blink with some Chrome Android UI pages. These
pages would disable top controls by setting the height to 0 but when we
scroll the page we calculate the "shown ratio" by dividing by height. This
the divided-by-0 value made its way down to Blink.

BUG=460007

Review URL: https://codereview.chromium.org/982333003

Cr-Commit-Position: refs/heads/master@{#319621}
parent 2e35995d
...@@ -104,6 +104,9 @@ gfx::Vector2dF TopControlsManager::ScrollBy( ...@@ -104,6 +104,9 @@ gfx::Vector2dF TopControlsManager::ScrollBy(
if (pinch_gesture_active_) if (pinch_gesture_active_)
return pending_delta; return pending_delta;
if (!TopControlsHeight())
return pending_delta;
if (permitted_state_ == SHOWN && pending_delta.y() > 0) if (permitted_state_ == SHOWN && pending_delta.y() > 0)
return pending_delta; return pending_delta;
else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include "cc/input/top_controls_manager.h" #include "cc/input/top_controls_manager.h"
#include <algorithm> #include <algorithm>
#include <cmath>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "cc/input/top_controls_manager_client.h" #include "cc/input/top_controls_manager_client.h"
...@@ -51,6 +53,9 @@ class MockTopControlsManagerClient : public TopControlsManagerClient { ...@@ -51,6 +53,9 @@ class MockTopControlsManagerClient : public TopControlsManagerClient {
float TopControlsHeight() const override { return top_controls_height_; } float TopControlsHeight() const override { return top_controls_height_; }
void SetCurrentTopControlsShownRatio(float ratio) override { void SetCurrentTopControlsShownRatio(float ratio) override {
ASSERT_FALSE(std::isnan(ratio));
ASSERT_FALSE(ratio == std::numeric_limits<float>::infinity());
ASSERT_FALSE(ratio == -std::numeric_limits<float>::infinity());
ratio = std::max(ratio, 0.f); ratio = std::max(ratio, 0.f);
ratio = std::min(ratio, 1.f); ratio = std::min(ratio, 1.f);
top_controls_shown_ratio_ = ratio; top_controls_shown_ratio_ = ratio;
...@@ -445,5 +450,20 @@ TEST(TopControlsManagerTest, ShrinkingHeightKeepsTopControlsHidden) { ...@@ -445,5 +450,20 @@ TEST(TopControlsManagerTest, ShrinkingHeightKeepsTopControlsHidden) {
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset()); EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
} }
TEST(TopControlsManagerTest, ScrollByWithZeroHeightControlsIsNoop) {
MockTopControlsManagerClient client(0.f, 0.5f, 0.5f);
TopControlsManager* manager = client.manager();
manager->UpdateTopControlsState(BOTH, BOTH, false);
manager->ScrollBegin();
gfx::Vector2dF pending = manager->ScrollBy(gfx::Vector2dF(0.f, 20.f));
EXPECT_FLOAT_EQ(20.f, pending.y());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
EXPECT_FLOAT_EQ(1.f, client.CurrentTopControlsShownRatio());
manager->ScrollEnd();
}
} // namespace } // namespace
} // namespace cc } // namespace cc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment