1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
// 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 ScrollState_h
#define ScrollState_h
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CoreExport.h"
#include "core/page/scrolling/ScrollStateInit.h"
#include "platform/scroll/ScrollStateData.h"
#include "wtf/Forward.h"
#include <deque>
#include <memory>
namespace blink {
class Element;
class CORE_EXPORT ScrollState final
: public GarbageCollectedFinalized<ScrollState>,
public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static ScrollState* create(ScrollStateInit);
static ScrollState* create(std::unique_ptr<ScrollStateData>);
~ScrollState() {}
// Web exposed methods.
// Reduce deltas by x, y.
void consumeDelta(double x, double y, ExceptionState&);
// Pops the first element off of |m_scrollChain| and calls |distributeScroll|
// on it.
void distributeToScrollChainDescendant();
int positionX() { return m_data->position_x; };
int positionY() { return m_data->position_y; };
// Positive when scrolling right.
double deltaX() const { return m_data->delta_x; };
// Positive when scrolling down.
double deltaY() const { return m_data->delta_y; };
// Indicates the smallest delta the input device can produce. 0 for
// unquantized inputs.
double deltaGranularity() const { return m_data->delta_granularity; };
// Positive if moving right.
double velocityX() const { return m_data->velocity_x; };
// Positive if moving down.
double velocityY() const { return m_data->velocity_y; };
// True for events dispatched after the users's gesture has finished.
bool inInertialPhase() const { return m_data->is_in_inertial_phase; };
// True if this is the first event for this scroll.
bool isBeginning() const { return m_data->is_beginning; };
// True if this is the last event for this scroll.
bool isEnding() const { return m_data->is_ending; };
// True if this scroll is the direct result of user input.
bool fromUserInput() const { return m_data->from_user_input; };
// True if this scroll is the result of the user interacting directly with
// the screen, e.g., via touch.
bool isDirectManipulation() const { return m_data->is_direct_manipulation; }
// True if this scroll is allowed to bubble upwards.
bool shouldPropagate() const { return m_data->should_propagate; };
// Non web exposed methods.
void consumeDeltaNative(double x, double y);
// TODO(tdresser): this needs to be web exposed. See crbug.com/483091.
void setScrollChain(std::deque<int> scrollChain) {
m_scrollChain = scrollChain;
}
Element* currentNativeScrollingElement() const;
void setCurrentNativeScrollingElement(Element*);
void setCurrentNativeScrollingElementById(int elementId);
bool deltaConsumedForScrollSequence() const {
return m_data->delta_consumed_for_scroll_sequence;
}
// Scroll begin and end must propagate to all nodes to ensure
// their state is updated.
bool fullyConsumed() const {
return !m_data->delta_x && !m_data->delta_y && !m_data->is_ending &&
!m_data->is_beginning;
}
ScrollStateData* data() const { return m_data.get(); }
DEFINE_INLINE_TRACE() {}
private:
ScrollState();
explicit ScrollState(std::unique_ptr<ScrollStateData>);
std::unique_ptr<ScrollStateData> m_data;
std::deque<int> m_scrollChain;
};
} // namespace blink
#endif // ScrollState_h
|