From: zhouleonlei Date: Mon, 1 Mar 2021 07:19:43 +0000 (+0800) Subject: Add APIs of webview back forward list X-Git-Tag: dali_2.0.22~7^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=cea4ca5eb2991a5845dd498e20c22cd178106ecb Add APIs of webview back forward list API added list: ewk_back_forward_list_previous_item_get ewk_back_forward_list_next_item_get Change-Id: Ia1f686d50d5805eca0ec179633c14c47d537f633 --- diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp index 14f2c1f..132075a 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp @@ -203,19 +203,31 @@ class MockWebEngineBackForwardList : public Dali::WebEngineBackForwardList { public: MockWebEngineBackForwardList() - : mockItem(), - pMockItem( &mockItem ) { } - Dali::WebEngineBackForwardListItem& GetCurrentItem() const override + std::unique_ptr GetCurrentItem() const override { - return *pMockItem; + std::unique_ptr ret(new MockWebEngineBackForwardListItem()); + return ret; } - Dali::WebEngineBackForwardListItem& GetItemAtIndex( uint32_t index ) const override + std::unique_ptr GetPreviousItem() const override { - return *pMockItem; + std::unique_ptr ret(new MockWebEngineBackForwardListItem()); + return ret; + } + + std::unique_ptr GetNextItem() const override + { + std::unique_ptr ret(new MockWebEngineBackForwardListItem()); + return ret; + } + + std::unique_ptr GetItemAtIndex( uint32_t index ) const override + { + std::unique_ptr ret(new MockWebEngineBackForwardListItem()); + return ret; } uint32_t GetItemCount() const override @@ -223,11 +235,24 @@ public: return 1; } -private: - MockWebEngineBackForwardListItem mockItem; - WebEngineBackForwardListItem* pMockItem; + std::vector> GetBackwardItems(int limit) override + { + std::vector> ret; + std::unique_ptr item(new MockWebEngineBackForwardListItem()); + ret.push_back(std::move(item)); + return ret; + } + + std::vector> GetForwardItems(int limit) override + { + std::vector> ret; + std::unique_ptr item(new MockWebEngineBackForwardListItem()); + ret.push_back(std::move(item)); + return ret; + } }; + class MockWebEngineCertificate : public Dali::WebEngineCertificate { public: diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index 034e377..a311131 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -162,7 +161,7 @@ static bool OnJavaScriptPrompt( const std::string& meesage1, const std::string& static void OnScreenshotCaptured(Dali::Toolkit::ImageView) { - gScreenshotCapturedCallbackCalled++; + gScreenshotCapturedCallbackCalled++; } static void OnVideoPlaying(bool isPlaying) @@ -1358,9 +1357,15 @@ int UtcDaliWebBackForwardListCheckItem(void) unsigned int itemCount = bfList->GetItemCount(); DALI_TEST_CHECK( itemCount == 1 ) - Dali::Toolkit::WebBackForwardListItem* citem = bfList->GetCurrentItem(); + std::unique_ptr citem = bfList->GetCurrentItem(); DALI_TEST_CHECK( citem != 0 ); + std::unique_ptr citemP = bfList->GetPreviousItem(); + DALI_TEST_CHECK( citemP != 0 ); + + std::unique_ptr citemN = bfList->GetNextItem(); + DALI_TEST_CHECK( citemN != 0 ); + const std::string kDefaultUrl( "http://url" ); std::string testValue = citem->GetUrl(); DALI_TEST_EQUALS( testValue, kDefaultUrl, TEST_LOCATION ); @@ -1373,9 +1378,15 @@ int UtcDaliWebBackForwardListCheckItem(void) testValue = citem->GetOriginalUrl(); DALI_TEST_EQUALS( testValue, kDefaultOriginalUrl, TEST_LOCATION ); - Dali::Toolkit::WebBackForwardListItem* item = bfList->GetItemAtIndex( 0 ); + std::unique_ptr item = bfList->GetItemAtIndex( 0 ); DALI_TEST_CHECK( item != 0 ); + std::vector> vecBack = bfList->GetBackwardItems(-1); + DALI_TEST_CHECK( vecBack.size() == 1 ); + + std::vector> vecForward = bfList->GetForwardItems(-1); + DALI_TEST_CHECK( vecForward.size() == 1 ); + END_TEST; } diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.cpp b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.cpp deleted file mode 100644 index f50a912..0000000 --- a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// EXTERNAL INCLUDES -#include - -namespace Dali -{ -namespace Toolkit -{ -const std::string EMPTY_STRING; - -WebBackForwardListItem::WebBackForwardListItem(const Dali::WebEngineBackForwardListItem* item) -: mWebEngineBackForwardListItem(item) -{ -} - -WebBackForwardListItem::~WebBackForwardListItem() -{ -} - -std::string WebBackForwardListItem::GetUrl() const -{ - return mWebEngineBackForwardListItem ? mWebEngineBackForwardListItem->GetUrl() : EMPTY_STRING; -} - -std::string WebBackForwardListItem::GetTitle() const -{ - return mWebEngineBackForwardListItem ? mWebEngineBackForwardListItem->GetTitle() : EMPTY_STRING; -} - -std::string WebBackForwardListItem::GetOriginalUrl() const -{ - return mWebEngineBackForwardListItem ? mWebEngineBackForwardListItem->GetOriginalUrl() : EMPTY_STRING; -} - -} // namespace Toolkit - -} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h deleted file mode 100644 index 2ae0e35..0000000 --- a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_ITEM_H -#define DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_ITEM_H - -/* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include - -// INTERNAL INCLUDES -#include - -namespace Dali -{ -class WebEngineBackForwardListItem; - -namespace Toolkit -{ -/** - * @addtogroup dali_toolkit_controls_web_view - * @{ - */ - -/** - * @brief WebBackForwardListItem is a class for back-forward list item of WebView. - * - * - * For working WebBackForwardListItem, a Dali::WebBackForwardListItem should be provided. - * - */ -class DALI_TOOLKIT_API WebBackForwardListItem -{ -public: - /** - * @brief Creates a WebBackForwardListItem. - */ - WebBackForwardListItem(const Dali::WebEngineBackForwardListItem* item); - - /** - * @brief Destructor. - */ - virtual ~WebBackForwardListItem() final; - - /** - * @brief Returns the URL of the item. - * - * @details The returned URL may differ from the original URL (For example, - * if the page is redirected). - * - * @return The URL of the @a item, otherwise "" in case of an error - */ - std::string GetUrl() const; - - /** - * @brief Returns the title of the item. - * - * @return The title of the @a item, otherwise "" in case of an error - */ - std::string GetTitle() const; - - /** - * @brief Returns the original URL of the item. - * - * @return The original URL of the @a item, otherwise "" in case of an error - */ - std::string GetOriginalUrl() const; - -private: - const Dali::WebEngineBackForwardListItem* mWebEngineBackForwardListItem; -}; - -/** - * @} - */ - -} // namespace Toolkit - -} // namespace Dali - -#endif // DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_ITEM_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp old mode 100644 new mode 100755 index 75014f0..8b3d8e1 --- a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp @@ -19,16 +19,14 @@ #include // EXTERNAL INCLUDES -#include #include namespace Dali { namespace Toolkit { -WebBackForwardList::WebBackForwardList(const Dali::WebEngineBackForwardList& list) -: mWebEngineBackForwardList(list), - mWebBackForwardListItem(0) +WebBackForwardList::WebBackForwardList(Dali::WebEngineBackForwardList& list) +: mWebEngineBackForwardList(list) { } @@ -36,16 +34,24 @@ WebBackForwardList::~WebBackForwardList() { } -WebBackForwardListItem* WebBackForwardList::GetCurrentItem() +std::unique_ptr WebBackForwardList::GetCurrentItem() { - mWebBackForwardListItem = WebBackForwardListItem(&mWebEngineBackForwardList.GetCurrentItem()); - return &mWebBackForwardListItem; + return mWebEngineBackForwardList.GetCurrentItem(); } -WebBackForwardListItem* WebBackForwardList::GetItemAtIndex(uint32_t index) +std::unique_ptr WebBackForwardList::GetPreviousItem() { - mWebBackForwardListItem = WebBackForwardListItem(&mWebEngineBackForwardList.GetItemAtIndex(index)); - return &mWebBackForwardListItem; + return mWebEngineBackForwardList.GetPreviousItem(); +} + +std::unique_ptr WebBackForwardList::GetNextItem() +{ + return mWebEngineBackForwardList.GetNextItem(); +} + +std::unique_ptr WebBackForwardList::GetItemAtIndex(uint32_t index) +{ + return mWebEngineBackForwardList.GetItemAtIndex(index); } uint32_t WebBackForwardList::GetItemCount() const @@ -53,6 +59,16 @@ uint32_t WebBackForwardList::GetItemCount() const return mWebEngineBackForwardList.GetItemCount(); } +std::vector> WebBackForwardList::GetBackwardItems(int limit) +{ + return mWebEngineBackForwardList.GetBackwardItems(limit); +} + +std::vector> WebBackForwardList::GetForwardItems(int limit) +{ + return mWebEngineBackForwardList.GetForwardItems(limit); +} + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h old mode 100644 new mode 100755 index 9dc81fc..0b015bc --- a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h +++ b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h @@ -18,8 +18,12 @@ * */ +// EXTERNAL INCLUDES +#include +#include +#include + // INTERNAL INCLUDES -#include #include namespace Dali @@ -48,7 +52,7 @@ public: /** * @brief Creates a WebBackForwardList. */ - WebBackForwardList(const Dali::WebEngineBackForwardList& list); + WebBackForwardList(Dali::WebEngineBackForwardList& list); /** * @brief Destructor. @@ -59,14 +63,26 @@ public: * @brief Returns the current item in the @a list. * @return The current item in list. */ - WebBackForwardListItem* GetCurrentItem(); + std::unique_ptr GetCurrentItem(); + + /** + * @brief Returns the previous item in the @a list. + * @return The previous item in list. + */ + std::unique_ptr GetPreviousItem(); + + /** + * @brief Returns the next item in the @a list. + * @return The next item in list. + */ + std::unique_ptr GetNextItem(); /** * @brief Returns the item at a given @a index relative to the current item. * @param[in] index The index of the item * @return The current item in list. */ - WebBackForwardListItem* GetItemAtIndex(uint32_t index); + std::unique_ptr GetItemAtIndex(uint32_t index); /** * @brief Returns the length of the back-forward list including the current @@ -76,9 +92,38 @@ public: */ uint32_t GetItemCount() const; + /** + * @brief Creates a list containing the items preceding the current item limited + * by @a limit. + * + * @details The WebEngineBackForwardListItem elements are located in the result + list starting with the oldest one.\n + * If @a limit is equal to @c -1 all the items preceding the current + * item are returned. + * + * @param[in] limit The number of items to retrieve + * + * @return @c vector containing @c WebEngineBackForwardListItem elements,\n + */ + std::vector> GetBackwardItems(int limit); + + /** + * @brief Creates the list containing the items following the current item + * limited by @a limit. + * + * @details The @c WebEngineBackForwardListItem elements are located in the result + * list starting with the oldest one.\n + * If @a limit is equal to @c -1 all the items preceding the current + * item are returned. + * + * @param[in] limit The number of items to retrieve + * + * @return @c vector containing @c WebEngineBackForwardListItem elements,\n + */ + std::vector> GetForwardItems(int limit); + private: - const Dali::WebEngineBackForwardList& mWebEngineBackForwardList; - Dali::Toolkit::WebBackForwardListItem mWebBackForwardListItem; + Dali::WebEngineBackForwardList& mWebEngineBackForwardList; }; /** diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index cc7dd45..334be34 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -39,7 +39,6 @@ SET( devel_api_src_files ${devel_api_src_dir}/controls/tool-bar/tool-bar.cpp ${devel_api_src_dir}/controls/video-view/video-view-devel.cpp ${devel_api_src_dir}/controls/web-view/web-back-forward-list.cpp - ${devel_api_src_dir}/controls/web-view/web-back-forward-list-item.cpp ${devel_api_src_dir}/controls/web-view/web-context.cpp ${devel_api_src_dir}/controls/web-view/web-cookie-manager.cpp ${devel_api_src_dir}/controls/web-view/web-form-repost-decision.cpp @@ -256,7 +255,6 @@ SET( devel_api_video_view_header_files SET( devel_api_web_view_header_files ${devel_api_src_dir}/controls/web-view/web-back-forward-list.h - ${devel_api_src_dir}/controls/web-view/web-back-forward-list-item.h ${devel_api_src_dir}/controls/web-view/web-context.h ${devel_api_src_dir}/controls/web-view/web-cookie-manager.h ${devel_api_src_dir}/controls/web-view/web-form-repost-decision.h