EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, false);
EINA_SAFETY_ON_NULL_RETURN_VAL(x, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(y, EINA_FALSE);
- impl->GetScrollPosition(x, y);
- return true;
+ return impl->GetScrollPosition(x, y);
}
Eina_Bool ewk_view_scroll_set(Evas_Object* view, int x, int y)
Eina_Bool ewk_view_scroll_size_get(const Evas_Object* view, int* width, int* height)
{
+ if (width)
+ *width = 0;
+ if (height)
+ *height = 0;
EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, EINA_FALSE);
impl->GetScrollSize(width,height);
return EINA_TRUE;
class utc_blink_ewk_view_scroll_pos_get : public utc_blink_ewk_base
{
protected:
- static void frameRendered(void* data, Evas_Object* eObject, void* dataFinished)
+ void LoadFinished(Evas_Object*)
{
- utc_message("[frameRendered] :: \n");
- if(data)
- static_cast<utc_blink_ewk_view_scroll_pos_get*>(data)->EventLoopStop(Success);
+ evas_object_focus_set(GetEwkWebView(), EINA_TRUE);
+ EventLoopStop(Success);
}
- /* Startup function */
- void PostSetUp()
+ static Eina_Bool quitMainLoop(void* data)
{
- evas_object_smart_callback_add(GetEwkWebView(), "frame,rendered", frameRendered, this);
- }
-
- /* Cleanup function */
- void PreTearDown()
- {
- evas_object_smart_callback_del(GetEwkWebView(), "frame,rendered", frameRendered);
+ if (data)
+ static_cast<utc_blink_ewk_view_scroll_pos_get*>(data)->EventLoopStop(Success);
+ return EINA_FALSE;
}
protected:
- static const char*const resource;
+ static const char* resource;
};
-const char*const utc_blink_ewk_view_scroll_pos_get::resource="/ewk_view/index_big_red_square.html";
+const char* utc_blink_ewk_view_scroll_pos_get::resource="/ewk_view/index_big_red_square.html";
/**
- * @brief Positive test case of ewk_view_scroll_pos_get(),tseting scroll postion against after set, and scroll
+ * @brief Positive test case of ewk_view_scroll_pos_get(), setting scroll position against after set, and scroll
*/
TEST_F(utc_blink_ewk_view_scroll_pos_get, POS_TEST1)
{
Eina_Bool result = EINA_FALSE;
if (x == valScrollSet && y == valScrollSet)
result = EINA_TRUE;
+ ASSERT_TRUE(result);
}
/**
- * @brief Positive test case of ewk_view_scroll_pos_get(),tseting scroll postion against after set, and scroll
+ * @brief Positive test case of ewk_view_scroll_pos_get(), setting scroll position against after set, and scroll
*/
TEST_F(utc_blink_ewk_view_scroll_pos_get, POS_TEST2)
{
utc_check_eq(result, EINA_TRUE);
}
+/**
+ * @brief ewk_view_scroll_pos_get() should return the same value as it has been set if main loop wasn't fired
+ */
+TEST_F(utc_blink_ewk_view_scroll_pos_get, POS_TEST3)
+{
+ int x = 0, y = 0;
+
+ ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),GetResourceUrl(resource).c_str()));
+ ASSERT_EQ(Success, EventLoopStart());
+
+ ASSERT_TRUE(ewk_view_scroll_set(GetEwkWebView(), 10, 10));
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_EQ(10, x);
+ ASSERT_EQ(10, y);
+
+ ASSERT_TRUE(ewk_view_scroll_set(GetEwkWebView(), 20, 20));
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_EQ(20, x);
+ ASSERT_EQ(20, y);
+}
+
+/**
+ * @brief ewk_view_scroll_pos_get() should return proper value after the engine tries to scroll over the page size
+ */
+TEST_F(utc_blink_ewk_view_scroll_pos_get, POS_TEST4)
+{
+ int x = 0, y = 0;
+
+ ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),GetResourceUrl(resource).c_str()));
+ ASSERT_EQ(Success, EventLoopStart());
+
+ int scrollSizeX = -1, scrollSizeY = -1;
+ ASSERT_TRUE(ewk_view_scroll_size_get(GetEwkWebView(), &scrollSizeX, &scrollSizeY));
+
+ int oversizeX = scrollSizeX + 100;
+ ASSERT_TRUE(ewk_view_scroll_set(GetEwkWebView(), oversizeX, 10));
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_EQ(scrollSizeX, x);
+ ASSERT_EQ(10, y);
+
+ ecore_timer_add(5.0f, quitMainLoop, this);
+ ASSERT_EQ(Success, EventLoopStart());
+
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_NE(scrollSizeX, x);
+ ASSERT_EQ(10, y);
+
+ // Now at the end of the page
+ ASSERT_TRUE(ewk_view_scroll_set(GetEwkWebView(), oversizeX, 10));
+ ecore_timer_add(5.0f, quitMainLoop, this);
+ ASSERT_EQ(Success, EventLoopStart());
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_EQ(scrollSizeX, x);
+}
+
+/**
+ * @brief Same as POS_TEST4, but with negative value
+ */
+TEST_F(utc_blink_ewk_view_scroll_pos_get, POS_TEST5)
+{
+ int x = 0, y = 0;
+
+ ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),GetResourceUrl(resource).c_str()));
+ ASSERT_EQ(Success, EventLoopStart());
+
+ ASSERT_TRUE(ewk_view_scroll_set(GetEwkWebView(), -100, 10));
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_EQ(0, x);
+ ASSERT_EQ(10, y);
+
+ ecore_timer_add(5.0f, quitMainLoop, this);
+ ASSERT_EQ(Success, EventLoopStart());
+
+ ASSERT_TRUE(ewk_view_scroll_pos_get(GetEwkWebView(), &x, &y));
+ ASSERT_EQ(0, x);
+ ASSERT_EQ(10, y);
+}
+
/**
* @brief Negative test case of ewk_view_scroll_pos_get(), testing for null
*/
*/
TEST_F(utc_blink_ewk_view_scroll_size_get, POS_TEST)
{
- if(!ewk_view_url_set(GetEwkWebView(),GetResourceUrl(resource).c_str()))
- utc_fail();
- if(Success!=EventLoopStart())
- utc_fail();
+ ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),GetResourceUrl(resource).c_str()));
+ ASSERT_EQ(Success, EventLoopStart());
- int xPossibleScrollArea, yPossibleScrollArea;
- utc_check_eq(ewk_view_scroll_size_get(GetEwkWebView(), &xPossibleScrollArea, &yPossibleScrollArea), EINA_TRUE);
+ int xPossibleScrollArea = 0, yPossibleScrollArea = 0;
+ ASSERT_TRUE(ewk_view_scroll_size_get(GetEwkWebView(), &xPossibleScrollArea, &yPossibleScrollArea));
+ ASSERT_GT(xPossibleScrollArea, 0);
+ ASSERT_GT(yPossibleScrollArea, 0);
}
/**
*/
TEST_F(utc_blink_ewk_view_scroll_size_get, NEG_TEST)
{
- int xPossibleScrollArea, yPossibleScrollArea;
- utc_check_eq(ewk_view_scroll_size_get(NULL, &xPossibleScrollArea,&yPossibleScrollArea), EINA_FALSE);
+ ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(),GetResourceUrl(resource).c_str()));
+ ASSERT_EQ(Success, EventLoopStart());
+
+ int xPossibleScrollArea = 0, yPossibleScrollArea = 0;
+ ASSERT_TRUE(ewk_view_scroll_size_get(GetEwkWebView(), NULL, &yPossibleScrollArea));
+ ASSERT_GT(yPossibleScrollArea, 0);
+
+ ASSERT_TRUE(ewk_view_scroll_size_get(GetEwkWebView(), &xPossibleScrollArea, NULL));
+ ASSERT_GT(xPossibleScrollArea, 0);
+
+ ASSERT_TRUE(ewk_view_scroll_size_get(GetEwkWebView(), NULL, NULL));
+
+ ASSERT_FALSE(ewk_view_scroll_size_get(NULL, &xPossibleScrollArea, &yPossibleScrollArea));
+ ASSERT_EQ(0, xPossibleScrollArea);
+ ASSERT_EQ(0, yPossibleScrollArea);
}
next_pixmap_id_(0),
surface_id_(0),
is_hw_accelerated_(true),
- is_modifier_key_(false) {
+ is_modifier_key_(false),
+ scroll_offset_changed_(false) {
#if defined(OS_TIZEN)
#if !defined(EWK_BRINGUP)
IPC_MESSAGE_HANDLER(EwkHostMsg_OrientationChangeEvent, OnOrientationChangeEvent)
IPC_MESSAGE_HANDLER(EwkViewMsg_SelectionTextStyleState, OnSelectionTextStyleState)
IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeMaxScrollOffset, OnDidChangeMaxScrollOffset)
+ IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeScrollOffset, OnDidChangeScrollOffset)
IPC_MESSAGE_HANDLER(EwkHostMsg_ReadMHTMLData, OnMHTMLContentGet)
IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangePageScaleFactor, OnDidChangePageScaleFactor)
IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangePageScaleRange, OnDidChangePageScaleRange)
scroll_detector_->SetMaxScroll(maxScrollX, maxScrollY);
}
+void RenderWidgetHostViewEfl::OnDidChangeScrollOffset(int scrollX, int scrollY) {
+ scroll_detector_->OnChangeScrollOffset(web_view_, gfx::Vector2d(scrollX, scrollY));
+ scroll_offset_changed_ = false;
+}
+
void RenderWidgetHostViewEfl::SelectRange(const gfx::Point& start, const gfx::Point& end) {
RenderViewHost* rvh = RenderViewHost::From(host_);
WebContentsImpl* wci = static_cast<WebContentsImpl*>(
host_->Send(new ViewMsg_SetViewMode(host_->GetRoutingID(), view_mode_for_blink));
}
+gfx::Vector2d RenderWidgetHostViewEfl::scroll_offset() const {
+ return scroll_detector_->GetLastScrollPosition();
+}
} // namespace content
void OnSelectionTextStyleState(const SelectionStylePrams& params);
void OnDidChangeMaxScrollOffset(int maxScrollX, int maxScrollY);
+ void OnDidChangeScrollOffset(int scrollX, int scrollY);
#ifdef OS_TIZEN
void FilterInputMotion(const blink::WebGestureEvent& gesture_event);
EWebView* eweb_view() const { return web_view_; }
RenderWidgetHostImpl* host() const { return host_; }
IMContextEfl* im_context() const { return im_context_; }
+ gfx::Vector2d scroll_offset() const;
float device_scale_factor() const { return device_scale_factor_; }
void SetComposition(const ui::CompositionText& composition_text);
void ConfirmComposition(base::string16& text);
+
+ bool IsScrollOffsetChanged() const { return scroll_offset_changed_; }
+ void SetScrollOffsetChanged() { scroll_offset_changed_ = true; }
protected:
friend class RenderWidgetHostView;
// The last scroll offset of the view.
gfx::Vector2dF last_scroll_offset_;
+ gfx::Point scroll_offset_;
+ bool scroll_offset_changed_;
gpu::Mailbox pending_mailbox_;
edge_Flag_(false) {
}
-void ScrollDetector::OnChangeScrollOffset(EWebView* web_view, const gfx::Vector2d& scroll_delta) {
+void ScrollDetector::OnChangeScrollOffset(EWebView* web_view,
+ const gfx::Vector2d& scroll_position) {
edge_Flag_ = true;
+ gfx::Vector2d scroll_delta = scroll_position;
+ scroll_delta -= last_scroll_position_;
+ last_scroll_position_ = scroll_position;
+
DetectEdge(web_view, scroll_delta);
if (edge_Flag_ && scroll_delta.x() > 0)
}
void ScrollDetector::DetectEdge(EWebView* web_view, const gfx::Vector2d& scroll_delta) {
- int x, y; //current scroll position
- web_view->GetScrollPosition(&x, &y);
-
- if (last_scroll_position_.x() != x)
- CheckForLeftRightEdges(web_view, x);
-
- if (last_scroll_position_.y() != y)
- CheckForTopBottomEdges(web_view, y);
+ if (scroll_delta.x()) {
+ CheckForLeftRightEdges(web_view, last_scroll_position_.x());
+ }
- last_scroll_position_.set_x(x);
- last_scroll_position_.set_y(y);
+ if (scroll_delta.y()) {
+ CheckForTopBottomEdges(web_view, last_scroll_position_.y());
+ }
}
void ScrollDetector::SetMaxScroll(int x, int y) {
class ScrollDetector {
public:
ScrollDetector();
- void OnChangeScrollOffset(EWebView* web_view, const gfx::Vector2d& scroll_delta);
+ void OnChangeScrollOffset(EWebView* web_view,
+ const gfx::Vector2d& scroll_position);
void SetMaxScroll(int x, int y);
+ gfx::Vector2d GetLastScrollPosition() const { return last_scroll_position_; }
private:
void DetectEdge(EWebView* web_view, const gfx::Vector2d& scroll_delta);
int, /*max scrollX*/
int /*max scrollY*/)
+IPC_MESSAGE_ROUTED2(EwkHostMsg_DidChangeScrollOffset,
+ int, /*scrollX*/
+ int /*scrollY*/)
+
IPC_MESSAGE_CONTROL3(EwkViewHostMsg_HitTestReply,
int, /* render_view_id */
_Ewk_Hit_Test, /* Ewk Hit test data without node map */
render_view_host->Send(new EwkViewMsg_Scale(render_view_host->GetRoutingID(), scale_factor, x, y));
}
-void EWebView::GetScrollPosition(int* x, int* y) const {
+bool EWebView::GetScrollPosition(int* x, int* y) const {
DCHECK(x);
DCHECK(y);
- const gfx::Vector2dF scroll_position = rwhv()->GetLastScrollOffset();
- *x = scroll_position.x();
- *y = scroll_position.y();
+ if (!rwhv()) {
+ *y = *x = 0;
+ return false;
+ }
+
+ if (rwhv()->IsScrollOffsetChanged()) {
+ *x = previous_scroll_position_.x();
+ *y = previous_scroll_position_.y();
+ } else {
+ const gfx::Vector2d scroll_position = rwhv()->scroll_offset();
+ *x = scroll_position.x();
+ *y = scroll_position.y();
+ }
+ return true;
}
void EWebView::SetScroll(int x, int y) {
if (!render_view_host)
return;
+ if (rwhv()) {
+ rwhv()->SetScrollOffsetChanged();
+ int maxX, maxY;
+ GetScrollSize(&maxX, &maxY);
+ previous_scroll_position_.set_x(std::min(std::max(x, 0), maxX));
+ previous_scroll_position_.set_y(std::min(std::max(y, 0), maxY));
+ }
+
render_view_host->Send(new EwkViewMsg_SetScroll(render_view_host->GetRoutingID(), x, y));
}
}
void EWebView::DidChangeContentsArea(int width, int height) {
- contents_area_ = gfx::Size(width, height);
}
void EWebView::DidChangeContentsSize(int width, int height) {
Eina_Rectangle last_view_port =
WebViewDelegate::GetInstance()->GetLastUsedViewPortArea(evas_object());
-#ifdef OS_TIZEN
- if (width && contents_area_.width() > last_view_port.w)
- *width = contents_area_.width() - last_view_port.w;
- if (height && contents_area_.height() > last_view_port.h)
- *height = contents_area_.height() - last_view_port.h;
-#else
if (width && contents_size_.width() > last_view_port.w)
*width = contents_size_.width() - last_view_port.w;
if (height && contents_size_.height() > last_view_port.h)
*height = contents_size_.height() - last_view_port.h;
-#endif
}
void EWebView::SelectRange(const gfx::Point& start, const gfx::Point& end) {
void ShowContextMenu(const content::ContextMenuParams& params, content::ContextMenuType type = content::MENU_TYPE_LINK);
void CancelContextMenu(int request_id);
void SetScale(double scale_factor, int x, int y);
- void GetScrollPosition(int* x, int* y) const;
+ bool GetScrollPosition(int* x, int* y) const;
void SetScroll(int x, int y);
void UrlRequestSet(const char* url, std::string method, Eina_Hash* headers, const char* body);
static int find_request_id_counter_;
IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
gfx::Size contents_size_;
- gfx::Size contents_area_;
double progress_;
mutable std::string title_;
_Ewk_Hit_Test hit_test_data_;
scoped_ptr<tizen_webview::BackForwardList> back_forward_list_;
private:
+ gfx::Vector2d previous_scroll_position_;
+
// only tizen_webview::WebView can create and delete this
EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
~EWebView();
if (!frame || (render_view()->GetWebView()->mainFrame() != frame))
return;
- if (max_scroll_offset_ != frame->maximumScrollOffset()) { //Check for change in MaxScrollOffset
+ if (max_scroll_offset_ != frame->maximumScrollOffset()) {
max_scroll_offset_ = frame->maximumScrollOffset();
Send(new EwkHostMsg_DidChangeMaxScrollOffset(render_view()->GetRoutingID(),
frame->maximumScrollOffset().width,
frame->maximumScrollOffset().height));
}
+
+ if(last_scroll_offset_ != frame->scrollOffset()) {
+ last_scroll_offset_ = frame->scrollOffset();
+ Send(new EwkHostMsg_DidChangeScrollOffset(render_view()->GetRoutingID(),
+ frame->scrollOffset().width,
+ frame->scrollOffset().height));
+ }
}
void RenderViewObserverEfl::OnGetSelectionStyle()
void OnSetViewMode(blink::WebViewMode view_mode);
blink::WebSize max_scroll_offset_;
+ blink::WebSize last_scroll_offset_;
float cached_min_page_scale_factor_;
float cached_max_page_scale_factor_;
gfx::Size last_sent_contents_size_;
return impl_->DidChangePageScaleRange(min_scale, max_scale);
}
-void WebView::GetScrollPosition(int* x, int* y) const {
+bool WebView::GetScrollPosition(int* x, int* y) const {
return impl_->GetScrollPosition(x, y);
}
void GetPageScaleRange(double *min_scale, double *max_scale);
void DidChangePageScaleRange(double min_scale, double max_scale);
// > View Scroll
- void GetScrollPosition(int* x, int* y) const;
+ bool GetScrollPosition(int* x, int* y) const;
void SetScroll(int x, int y); // TODO: rename to ScrollTo (x,y) x,y is left top (see GetScrollSize)
void GetScrollSize(int* w, int* h); // TODO: rename to GetPossibleScrollSize
// > View Orientation