From: David Steele Date: Wed, 15 Mar 2017 13:25:58 +0000 (+0000) Subject: Encapsulated visual URL in new VisualUrl class. X-Git-Tag: dali_1.2.32~8^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=8cfc7965881ba756bca7bdde98b548200a649bd4 Encapsulated visual URL in new VisualUrl class. The VisualUrl object encapsulates the URL string and also resolves the data type and whether the url is local or remote on creation. Change-Id: I88cfc98563799d2646bde1911a5e8e90496ffd45 Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index 023d4bc..6ec6207 100755 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -17,7 +17,7 @@ SET(TC_SOURCES utc-Dali-VisualModel.cpp utc-Dali-Text-Layout.cpp utc-Dali-Text-Controller.cpp - utc-Dali-VisualFactoryResolveUrl.cpp + utc-Dali-VisualUrl.cpp utc-Dali-Text-Markup.cpp utc-Dali-Text-Typesetter.cpp utc-Dali-Text-ViewModel.cpp diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualFactoryResolveUrl.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualFactoryResolveUrl.cpp deleted file mode 100644 index 8235355..0000000 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualFactoryResolveUrl.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2016 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. - * - */ - -#include - -#include - -#include -#include - -using namespace Dali::Toolkit::Internal; - -int UtcDaliResolveUrlRegularImage(void) -{ - tet_infoline( "UtcDaliResolveUrl REGULAR_IMAGE" ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.jpeg"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.PNG"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.Png123"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.Png1.23"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType(""), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType(" "), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("."), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("9"), TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliResolveUrlSvg(void) -{ - tet_infoline( "UtcDaliResolveUrl SVG" ); - - DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.svg"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.svg.svg"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.svG"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.SVG"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType(".SvG"), TEST_LOCATION ); - - // SVGs aren't N-patch - DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.9.svg"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.png"), TEST_LOCATION ); - - // maybe controversial, but for now we expect the suffix to be exactly .svg - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.svg1"), TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliResolveUrlNPatch(void) -{ - tet_infoline( "UtcDaliResolveUrl N_PATCH" ); - - DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.#.png"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.9.9.bmp"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.9.9.jpg[]=$$"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.9.#.#.9.wbpm123"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.##.png"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.99.jpeg"), TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliResolveUrlGif(void) -{ - tet_infoline( "UtcDaliResolveUrl GIF" ); - - DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.gif"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.gif.gif"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.giF"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.GIF"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType(".GiF"), TEST_LOCATION ); - - // GIFs aren't N-patch - DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.9.gif"), TEST_LOCATION ); - - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("gif.png"), TEST_LOCATION ); - DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("gif.gif1"), TEST_LOCATION ); - - END_TEST; -} diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualUrl.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualUrl.cpp new file mode 100644 index 0000000..476a023 --- /dev/null +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualUrl.cpp @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2016 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. + * + */ + +#include + +#include + +#include +#include + +using namespace Dali::Toolkit::Internal; + +int UtcDaliVisualUrlConstructor(void) +{ + const char* url="http://bar.org/foobar.gif"; + VisualUrl visualUrl(url); + DALI_TEST_EQUALS( true, visualUrl.IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( visualUrl.GetType(), VisualUrl::GIF, TEST_LOCATION ); + DALI_TEST_EQUALS( visualUrl.GetLocation(), VisualUrl::REMOTE, TEST_LOCATION ); + + VisualUrl visualUrl2("foobar.jpeg"); + visualUrl2 = visualUrl; + DALI_TEST_EQUALS( true, visualUrl2.IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( visualUrl2.GetType(), VisualUrl::GIF, TEST_LOCATION ); + DALI_TEST_EQUALS( visualUrl2.GetLocation(), VisualUrl::REMOTE, TEST_LOCATION ); + + VisualUrl visualUrl3( visualUrl ); + DALI_TEST_EQUALS( true, visualUrl3.IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( visualUrl3.GetType(), VisualUrl::GIF, TEST_LOCATION ); + DALI_TEST_EQUALS( visualUrl3.GetLocation(), VisualUrl::REMOTE, TEST_LOCATION ); + END_TEST; +} + + +int UtcDaliVisualUrlRegularImage(void) +{ + tet_infoline( "UtcDaliVisualUrl REGULAR_IMAGE" ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.jpeg").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.PNG").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.Png123").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.Png1.23").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl(" ").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl(".").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("9").GetType(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliVisualUrlSvg(void) +{ + tet_infoline( "UtcDaliVisualUrl SVG" ); + + DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.svg").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.svg.svg").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.svG").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.SVG").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl(".SvG").GetType(), TEST_LOCATION ); + + // SVGs aren't N-patch + DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.9.svg").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.png").GetType(), TEST_LOCATION ); + + // maybe controversial, but for now we expect the suffix to be exactly .svg + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.svg1").GetType(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliVisualUrlNPatch(void) +{ + tet_infoline( "UtcDaliVisualUrl N_PATCH" ); + + DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.#.png").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.9.9.bmp").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.9.9.jpg[]=$$").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.9.#.#.9.wbpm123").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.##.png").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.99.jpeg").GetType(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliVisualUrlGif(void) +{ + tet_infoline( "UtcDaliVisualUrl GIF" ); + + DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.gif").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.gif.gif").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.giF").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.GIF").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl(".GiF").GetType(), TEST_LOCATION ); + + // GIFs aren't N-patch + DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.9.gif").GetType(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("gif.png").GetType(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("gif.gif1").GetType(), TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliVisualUrlLocationP(void) +{ + tet_infoline( "UtcDaliVisualUrl Location" ); + + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.jpeg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://BAR.ORG/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://BAR.ORG/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliVisualUrlLocationN(void) +{ + tet_infoline( "UtcDaliVisualUrl Location negative tests" ); + + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("htp://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("htpp://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("sshttp://bar.org/foobar.svg").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("htth://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("http:https://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("https:http://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("HPPT://bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("ftp:/bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("ssh;//bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("ssh:/bar.org/foobar.9.png").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("http:/bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("https:/bar.org/foobar.gif").GetLocation(), TEST_LOCATION ); + + DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.png").GetLocation(), TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliVisualUrlIsLocal(void) +{ + tet_infoline( "UtcDaliVisualUrl IsLocal" ); + + DALI_TEST_EQUALS( true, VisualUrl("foobar.gif").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.png").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.svg").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.GIF").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.9.png").IsLocal(), TEST_LOCATION ); + + DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.gif").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.png").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.svg").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION ); + + DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.gif").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.png").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.svg").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION ); + + DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.gif").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.png").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.svg").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION ); + + DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.gif").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.png").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.svg").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliVisualUrlIsValid(void) +{ + tet_infoline( "UtcDaliVisualUrl IsValid" ); + + DALI_TEST_EQUALS( false, VisualUrl().IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( false, VisualUrl("").IsValid(), TEST_LOCATION ); + + DALI_TEST_EQUALS( true, VisualUrl("foobar.gif").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.png").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.svg").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.GIF").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("foobar.9.png").IsValid(), TEST_LOCATION ); + + DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.gif").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.png").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.svg").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.GIF").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.9.png").IsValid(), TEST_LOCATION ); + + DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.gif").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.png").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.svg").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.GIF").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.9.png").IsValid(), TEST_LOCATION ); + + DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.gif").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.png").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.svg").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.GIF").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.9.png").IsValid(), TEST_LOCATION ); + + DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.gif").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.png").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.svg").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.GIF").IsValid(), TEST_LOCATION ); + DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.9.png").IsValid(), TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp b/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp index 421083f..ad65aea 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp @@ -30,6 +30,8 @@ #include #include +#include + using namespace Dali; using namespace Toolkit; @@ -741,8 +743,11 @@ int UtcDaliPushButtonPaddingLayout(void) PushButton pushButton = PushButton::New(); const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f ); - const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f ); - const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f); + const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f ); + + // Get actual size of test image + ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE ); + const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() ); pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); @@ -800,8 +805,6 @@ int UtcDaliPushButtonPaddingLayout(void) Stage::GetCurrent().Add( pushButton ); - TestPlatformAbstraction& platform = application.GetPlatform(); - platform.SetClosestImageSize( TEST_IMAGE_SIZE ); pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" ); pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE ); @@ -824,7 +827,7 @@ int UtcDaliPushButtonPaddingLayout(void) size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height ); - const Vector2 expectedIconAndPaddingSize( TEST_ICON_PADDING.x+TEST_ICON_PADDING.y+TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w+TEST_ICON_PADDING.z +TEST_IMAGE_SIZE.height ); + const Vector2 expectedIconAndPaddingSize( TEST_ICON_PADDING.x+TEST_ICON_PADDING.y+TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w + TEST_ICON_PADDING.z + TEST_IMAGE_SIZE.height ); DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); // Now test padding for both label and icon simultaneously. @@ -847,7 +850,8 @@ int UtcDaliPushButtonPaddingLayout(void) tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height ); DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION ); - DALI_TEST_GREATER( size.height, expectedIconAndPaddingSize.width, TEST_LOCATION ); // Test height of control is greater than icon and padding. As Text set to larger values. + // Test height of control is same as icon and padding, as Text is smaller than icon + DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION ); END_TEST; } @@ -885,7 +889,10 @@ int UtcDaliPushButtonAlignmentLayout(void) const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f ); const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f ); - const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f); + + // Get actual size of test image + ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE ); + const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() ); PushButton pushButton = PushButton::New(); @@ -925,9 +932,6 @@ int UtcDaliPushButtonAlignmentLayout(void) const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ), ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) ); - TestPlatformAbstraction& platform = application.GetPlatform(); - platform.SetClosestImageSize( TEST_IMAGE_SIZE ); - // Add Icon and set its alignment pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" ); pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE ); diff --git a/dali-toolkit/internal/file.list b/dali-toolkit/internal/file.list index b787acd..12c2274 100755 --- a/dali-toolkit/internal/file.list +++ b/dali-toolkit/internal/file.list @@ -11,29 +11,30 @@ toolkit_src_files = \ $(toolkit_src_dir)/builder/style.cpp \ $(toolkit_src_dir)/builder/tree-node-manipulator.cpp \ $(toolkit_src_dir)/builder/replacement.cpp \ - $(toolkit_src_dir)/visuals/visual-base-impl.cpp \ - $(toolkit_src_dir)/visuals/visual-base-data-impl.cpp \ - $(toolkit_src_dir)/visuals/image-atlas-manager.cpp \ - $(toolkit_src_dir)/visuals/npatch-loader.cpp \ - $(toolkit_src_dir)/visuals/visual-factory-cache.cpp \ - $(toolkit_src_dir)/visuals/visual-factory-impl.cpp \ - $(toolkit_src_dir)/visuals/visual-string-constants.cpp \ $(toolkit_src_dir)/visuals/animated-image/animated-image-visual.cpp \ $(toolkit_src_dir)/visuals/border/border-visual.cpp \ $(toolkit_src_dir)/visuals/color/color-visual.cpp \ + $(toolkit_src_dir)/visuals/gradient/gradient-visual.cpp \ $(toolkit_src_dir)/visuals/gradient/gradient.cpp \ $(toolkit_src_dir)/visuals/gradient/linear-gradient.cpp \ $(toolkit_src_dir)/visuals/gradient/radial-gradient.cpp \ - $(toolkit_src_dir)/visuals/gradient/gradient-visual.cpp \ + $(toolkit_src_dir)/visuals/image-atlas-manager.cpp \ $(toolkit_src_dir)/visuals/image/image-visual.cpp \ $(toolkit_src_dir)/visuals/mesh/mesh-visual.cpp \ + $(toolkit_src_dir)/visuals/npatch-loader.cpp \ $(toolkit_src_dir)/visuals/npatch/npatch-visual.cpp \ $(toolkit_src_dir)/visuals/primitive/primitive-visual.cpp \ $(toolkit_src_dir)/visuals/svg/svg-rasterize-thread.cpp \ $(toolkit_src_dir)/visuals/svg/svg-visual.cpp \ $(toolkit_src_dir)/visuals/text/text-visual.cpp \ - $(toolkit_src_dir)/visuals/wireframe/wireframe-visual.cpp \ $(toolkit_src_dir)/visuals/transition-data-impl.cpp \ + $(toolkit_src_dir)/visuals/visual-base-data-impl.cpp \ + $(toolkit_src_dir)/visuals/visual-base-impl.cpp \ + $(toolkit_src_dir)/visuals/visual-factory-cache.cpp \ + $(toolkit_src_dir)/visuals/visual-factory-impl.cpp \ + $(toolkit_src_dir)/visuals/visual-string-constants.cpp \ + $(toolkit_src_dir)/visuals/visual-url.cpp \ + $(toolkit_src_dir)/visuals/wireframe/wireframe-visual.cpp \ $(toolkit_src_dir)/controls/alignment/alignment-impl.cpp \ $(toolkit_src_dir)/controls/bloom-view/bloom-view-impl.cpp \ $(toolkit_src_dir)/controls/bubble-effect/bubble-emitter-impl.cpp \ diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp index 2512baf..217994e 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp @@ -54,7 +54,7 @@ const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); } -AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ) +AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) { AnimatedImageVisual* visual = new AnimatedImageVisual( factoryCache ); visual->mImageUrl = imageUrl; @@ -63,7 +63,7 @@ AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCach return visual; } -AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl ) +AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) { AnimatedImageVisual* visual = new AnimatedImageVisual( factoryCache ); visual->mImageUrl = imageUrl; @@ -90,7 +90,7 @@ void AnimatedImageVisual::GetNaturalSize( Vector2& naturalSize ) { if( mImageSize.GetWidth() == 0 && mImageSize.GetHeight() == 0) { - mImageSize = Dali::GetGifImageSize( mImageUrl ); + mImageSize = Dali::GetGifImageSize( mImageUrl.GetUrl() ); } naturalSize.width = mImageSize.GetWidth(); @@ -103,9 +103,9 @@ void AnimatedImageVisual::DoCreatePropertyMap( Property::Map& map ) const map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_IMAGE ); - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { - map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl ); + map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() ); } map.Insert( Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea ); @@ -221,12 +221,16 @@ Texture AnimatedImageVisual::PrepareAnimatedImage() { // load from image file std::vector pixelDataList; - if( Dali::LoadAnimatedGifFromFile( mImageUrl.c_str() , pixelDataList, mFrameDelayContainer ) ) + + if( mImageUrl.IsLocal() ) { - mImageSize.SetWidth( pixelDataList[0].GetWidth() ); - mImageSize.SetHeight( pixelDataList[0].GetHeight() ); + if( Dali::LoadAnimatedGifFromFile( mImageUrl.GetUrl().c_str() , pixelDataList, mFrameDelayContainer ) ) + { + mImageSize.SetWidth( pixelDataList[0].GetWidth() ); + mImageSize.SetHeight( pixelDataList[0].GetHeight() ); - return Toolkit::ImageAtlas::PackToAtlas( pixelDataList, mTextureRectContainer ); + return Toolkit::ImageAtlas::PackToAtlas( pixelDataList, mTextureRectContainer ); + } } return Texture(); diff --git a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h index e89fec6..4e11cce 100644 --- a/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-image/animated-image-visual.h @@ -26,6 +26,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -77,7 +78,7 @@ public: * @param[in] properties A Property::Map containing settings for this visual * @return A smart-pointer to the newly allocated visual. */ - static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ); + static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ); /** * @brief Create the animated image visual using the image URL. @@ -85,7 +86,7 @@ public: * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @param[in] imageUrl The URL to animated image resource to use */ - static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl ); + static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ); public: // from Visual @@ -163,7 +164,7 @@ private: Dali::Vector mTextureRectContainer; Dali::Vector mFrameDelayContainer; Vector4 mPixelArea; - std::string mImageUrl; + VisualUrl mImageUrl; ImageDimensions mImageSize; uint32_t mCurrentFrameIndex; diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 812e854..49e2c00 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -18,17 +18,18 @@ // CLASS HEADER #include -// EXTERNAL HEADER -#include // for strncasecmp +// EXTERNAL HEADERS +#include // for strlen() #include #include #include #include +#include #include #include #include -// INTERNAL HEADER +// INTERNAL HEADERS #include #include #include @@ -37,6 +38,7 @@ #include #include #include +#include namespace Dali { @@ -49,8 +51,6 @@ namespace Internal namespace { -const char HTTP_URL[] = "http://"; -const char HTTPS_URL[] = "https://"; // property names const char * const IMAGE_FITTING_MODE( "fittingMode" ); @@ -213,7 +213,7 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS } // unnamed namespace ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, - const std::string& imageUrl, + const VisualUrl& imageUrl, const Property::Map& properties, ImageDimensions size, FittingMode::Type fittingMode, @@ -225,7 +225,7 @@ ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, } ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, - const std::string& imageUrl, + const VisualUrl& imageUrl, ImageDimensions size, FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode ) @@ -239,7 +239,7 @@ ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, const Image& } ImageVisual::ImageVisual( VisualFactoryCache& factoryCache, - const std::string& imageUrl, + const VisualUrl& imageUrl, ImageDimensions size, FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode ) @@ -323,7 +323,7 @@ void ImageVisual::DoSetProperties( const Property::Map& propertyMap ) } } - if( mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING && mImageUrl.size() > 0u ) + if( mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING && mImageUrl.IsValid() ) { // if sync loading is required, the loading should start // immediately when new image url is set or the actor is off stage @@ -440,9 +440,9 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize ) naturalSize.y = mDesiredSize.GetHeight(); return; } - else if( !mImageUrl.empty() ) + else if( mImageUrl.IsValid() && mImageUrl.GetLocation() == VisualUrl::LOCAL ) { - ImageDimensions dimentions = ResourceImage::GetImageSize( mImageUrl ); + ImageDimensions dimentions = Dali::GetClosestImageSize( mImageUrl.GetUrl() ); naturalSize.x = dimentions.GetWidth(); naturalSize.y = dimentions.GetHeight(); return; @@ -553,15 +553,15 @@ bool ImageVisual::IsSynchronousResourceLoading() const void ImageVisual::LoadResourceSynchronously() { - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { - BitmapLoader loader = BitmapLoader::New( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode ); + BitmapLoader loader = BitmapLoader::New( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode ); loader.Load(); mPixels = loader.GetPixelData(); } } -TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading, bool attemptAtlasing ) +TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing ) { TextureSet textureSet; textureRect = FULL_TEXTURE_RECT; @@ -595,13 +595,13 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::strin { if( attemptAtlasing ) { - textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, url, mDesiredSize, mFittingMode, true, this ); + textureSet = mFactoryCache.GetAtlasManager()->Add( textureRect, mImageUrl.GetUrl(), mDesiredSize, mFittingMode, true, this ); mImpl->mFlags |= Impl::IS_ATLASING_APPLIED; } if( !textureSet ) // big image, no atlasing or atlasing failed { mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED; - ResourceImage resourceImage = Dali::ResourceImage::New( url, mDesiredSize, mFittingMode, mSamplingMode ); + ResourceImage resourceImage = Dali::ResourceImage::New( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode ); resourceImage.LoadingFinishedSignal().Connect( this, &ImageVisual::OnImageLoaded ); textureSet = TextureSet::New(); TextureSetImage( textureSet, 0u, resourceImage ); @@ -617,21 +617,18 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::strin return textureSet; } -void ImageVisual::InitializeRenderer( const std::string& imageUrl ) +void ImageVisual::InitializeRenderer() { - mImageUrl = imageUrl; mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED; - if( !mImpl->mCustomShader && - ( strncasecmp( imageUrl.c_str(), HTTP_URL, sizeof(HTTP_URL) -1 ) != 0 ) && // dont atlas remote images - ( strncasecmp( imageUrl.c_str(), HTTPS_URL, sizeof(HTTPS_URL) -1 ) != 0 ) ) + if( !mImpl->mCustomShader && mImageUrl.GetLocation() == VisualUrl::LOCAL ) { bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE; Vector4 atlasRect; // texture set has to be created first as we need to know if atlasing succeeded or not // when selecting the shader - TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true ); + TextureSet textures = CreateTextureSet( atlasRect, IsSynchronousResourceLoading(), true ); CreateRenderer( textures ); if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas @@ -649,7 +646,7 @@ void ImageVisual::InitializeRenderer( const std::string& imageUrl ) { // for custom shader or remote image, atlas is not applied Vector4 atlasRect; // ignored in this case - TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), false ); + TextureSet textures = CreateTextureSet( atlasRect, IsSynchronousResourceLoading(), false ); CreateRenderer( textures ); } } @@ -689,9 +686,9 @@ void ImageVisual::UploadCompleted() void ImageVisual::DoSetOnStage( Actor& actor ) { - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { - InitializeRenderer( mImageUrl ); + InitializeRenderer(); } else if ( mImage ) { @@ -723,9 +720,9 @@ void ImageVisual::DoSetOffStage( Actor& actor ) //If we own the image then make sure we release it when we go off stage actor.RemoveRenderer( mImpl->mRenderer); - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { - RemoveFromAtlas(mImageUrl); + RemoveFromAtlas( mImageUrl.GetUrl() ); mImage.Reset(); } @@ -740,9 +737,9 @@ void ImageVisual::DoCreatePropertyMap( Property::Map& map ) const bool sync = IsSynchronousResourceLoading(); map.Insert( SYNCHRONOUS_LOADING, sync ); - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { - map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl ); + map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() ); map.Insert( Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth() ); map.Insert( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight() ); } @@ -770,7 +767,7 @@ void ImageVisual::DoCreateInstancePropertyMap( Property::Map& map ) const { map.Clear(); map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::Visual::IMAGE ); - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { map.Insert( Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth() ); map.Insert( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight() ); diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index bf71048..83fd71c 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -26,8 +26,9 @@ #include // INTERNAL INCLUDES -#include #include +#include +#include namespace Dali { @@ -108,7 +109,7 @@ public: * @return A smart-pointer to the newly allocated visual. */ static ImageVisualPtr New( VisualFactoryCache& factoryCache, - const std::string& imageUrl, + const VisualUrl& imageUrl, const Property::Map& properties, ImageDimensions size = ImageDimensions(), FittingMode::Type fittingMode = FittingMode::DEFAULT, @@ -127,7 +128,7 @@ public: * @return A smart-pointer to the newly allocated visual. */ static ImageVisualPtr New( VisualFactoryCache& factoryCache, - const std::string& imageUrl, + const VisualUrl& imageUrl, ImageDimensions size = ImageDimensions(), FittingMode::Type fittingMode = FittingMode::DEFAULT, Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); @@ -171,7 +172,7 @@ protected: * @param[in] samplingMode The SamplingMode of the resource to load */ ImageVisual( VisualFactoryCache& factoryCache, - const std::string& imageUrl, + const VisualUrl& imageUrl, ImageDimensions size, FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode ); @@ -237,11 +238,9 @@ private: void ApplyImageToSampler( const Image& image ); /** - * @brief Initializes the Dali::Renderer from an image url string - * - * @param[in] imageUrl The image url string to intialize this ImageVisual from + * @brief Initializes the Dali::Renderer from the image url */ - void InitializeRenderer( const std::string& imageUrl ); + void InitializeRenderer(); /** * @brief Initializes the Dali::Renderer from an image handle @@ -281,7 +280,7 @@ private: * @param[in] attemptAtlasing If true will attempt atlasing, otherwise create unique texture * @return the texture set to use */ - TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading, bool attemptAtlasing ); + TextureSet CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing ); /** * Callback function of image resource loading succeed @@ -313,7 +312,7 @@ private: PixelData mPixels; Vector4 mPixelArea; WeakHandle mPlacementActor; - std::string mImageUrl; + VisualUrl mImageUrl; Dali::ImageDimensions mDesiredSize; Dali::FittingMode::Type mFittingMode:3; diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 9b94eb5..36700fe 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -234,7 +234,7 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co /////////////////NPatchVisual//////////////// -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) { NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); nPatchVisual->mImageUrl = imageUrl; @@ -243,7 +243,7 @@ NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std:: return nPatchVisual; } -NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) { NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); nPatchVisual->mImageUrl = imageUrl; @@ -254,8 +254,8 @@ NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std:: NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image ) { NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) ); - nPatchVisual->mImageUrl = image.GetUrl(); - + VisualUrl visualUrl( image.GetUrl() ); + nPatchVisual->mImageUrl = visualUrl; return nPatchVisual; } @@ -263,10 +263,11 @@ void NPatchVisual::GetNaturalSize( Vector2& naturalSize ) { naturalSize.x = 0u; naturalSize.y = 0u; + // load now if not already loaded - if( NPatchLoader::UNINITIALIZED_ID == mId ) + if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocal() ) { - mId = mLoader.Load( mImageUrl, mBorder ); + mId = mLoader.Load( mImageUrl.GetUrl(), mBorder ); } const NPatchLoader::Data* data; if( mLoader.GetNPatchData( mId, data ) ) @@ -304,9 +305,9 @@ void NPatchVisual::DoSetProperties( const Property::Map& propertyMap ) void NPatchVisual::DoSetOnStage( Actor& actor ) { // load when first go on stage - if( NPatchLoader::UNINITIALIZED_ID == mId ) + if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocal() ) { - mId = mLoader.Load( mImageUrl, mBorder ); + mId = mLoader.Load( mImageUrl.GetUrl(), mBorder ); } Geometry geometry = CreateGeometry(); @@ -336,7 +337,7 @@ void NPatchVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::N_PATCH ); - map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl ); + map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() ); map.Insert( Toolkit::ImageVisual::Property::BORDER_ONLY, mBorderOnly ); map.Insert( Toolkit::DevelImageVisual::Property::BORDER, mBorder ); } @@ -491,7 +492,7 @@ void NPatchVisual::ApplyTextureAndUniforms() } else { - DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.c_str() ); + DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str() ); TextureSet textureSet = TextureSet::New(); mImpl->mRenderer.SetTextures( textureSet ); Image croppedImage = VisualFactoryCache::GetBrokenVisualImage(); diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index a36f780..901211d 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -29,6 +29,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -68,7 +69,7 @@ public: * @param[in] properties A Property::Map containing settings for this visual * @return A smart-pointer to the newly allocated visual. */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ); /** * @brief Create an N-patch visual using an image URL. @@ -79,7 +80,7 @@ public: * @param[in] imageUrl The URL to 9 patch image resource to use * @return A smart-pointer to the newly allocated visual. */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ); /** * @brief Create an N-patch visual with a NinePatchImage resource. @@ -202,7 +203,7 @@ private: private: NPatchLoader& mLoader; ///< reference to N patch loader for fast access - std::string mImageUrl; ///< The url to the N patch to load + VisualUrl mImageUrl; ///< The url to the N patch to load std::size_t mId; ///< id of the N patch (from loader/cache) bool mBorderOnly; ///< if only border is desired Rect< int > mBorder; ///< The size of the border diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 7676a53..7fc1cf2 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -53,7 +53,7 @@ namespace Toolkit namespace Internal { -SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ) +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ) { SvgVisualPtr svgVisual( new SvgVisual( factoryCache ) ); svgVisual->ParseFromUrl( imageUrl ); @@ -62,7 +62,7 @@ SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string return svgVisual; } -SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl ) +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ) { SvgVisualPtr svgVisual( new SvgVisual( factoryCache ) ); svgVisual->ParseFromUrl( imageUrl ); @@ -73,7 +73,7 @@ SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mAtlasRect( FULL_TEXTURE_RECT ), - mImageUrl(), + mImageUrl( ), mParsedImage( NULL ), mPlacementActor(), mVisualSize(Vector2::ZERO) @@ -138,9 +138,9 @@ void SvgVisual::DoCreatePropertyMap( Property::Map& map ) const { map.Clear(); map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::SVG ); - if( !mImageUrl.empty() ) + if( mImageUrl.IsValid() ) { - map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl ); + map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() ); } } @@ -149,13 +149,15 @@ void SvgVisual::DoCreateInstancePropertyMap( Property::Map& map ) const // Do nothing } -void SvgVisual::ParseFromUrl( const std::string& imageUrl ) +void SvgVisual::ParseFromUrl( const VisualUrl& imageUrl ) { mImageUrl = imageUrl; - - Vector2 dpi = Stage::GetCurrent().GetDpi(); - float meanDpi = (dpi.height + dpi.width) * 0.5f; - mParsedImage = nsvgParseFromFile( imageUrl.c_str(), UNITS, meanDpi ); + if( mImageUrl.IsLocal() ) + { + Vector2 dpi = Stage::GetCurrent().GetDpi(); + float meanDpi = (dpi.height + dpi.width) * 0.5f; + mParsedImage = nsvgParseFromFile( mImageUrl.GetUrl().c_str(), UNITS, meanDpi ); + } } void SvgVisual::AddRasterizationTask( const Vector2& size ) diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index 3369901..0d5dcf8 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include +#include struct NSVGimage; @@ -64,7 +65,7 @@ public: * @param[in] properties A Property::Map containing settings for this visual * @return A smart-pointer to the newly allocated visual. */ - static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ); + static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties ); /** * @brief Create the SVG Visual using the image URL. @@ -76,7 +77,7 @@ public: * @param[in] imageUrl The URL to svg resource to use * @return A smart-pointer to the newly allocated visual. */ - static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl ); + static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl ); public: // from Visual @@ -145,7 +146,7 @@ private: * * @param[in] imageUrl The URL of the image to parse the SVG from. */ - void ParseFromUrl( const std::string& imageUrl ); + void ParseFromUrl( const VisualUrl& imageUrl ); /** * @bried Rasterize the svg with the given size, and add it to the visual. @@ -163,7 +164,7 @@ private: private: Vector4 mAtlasRect; - std::string mImageUrl; + VisualUrl mImageUrl; NSVGimage* mParsedImage; WeakHandle mPlacementActor; Vector2 mVisualSize; diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 455a8ac..8a5d245 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include namespace Dali @@ -121,26 +121,32 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property std::string imageUrl; if( imageURLValue && imageURLValue->Get( imageUrl ) ) { - // first resolve url type to know which visual to create - UrlType::Type type = ResolveUrlType( imageUrl ); - if( UrlType::N_PATCH == type ) - { - visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap ); - } - else if( UrlType::SVG == type ) - { - visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap ); - } - else if( UrlType::GIF == type ) - { - visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap ); - } - else // Regular image + VisualUrl visualUrl( imageUrl ); + + switch( visualUrl.GetType() ) { - visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap ); + case VisualUrl::N_PATCH: + { + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } + case VisualUrl::SVG: + { + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } + case VisualUrl::GIF: + { + visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } + case VisualUrl::REGULAR_IMAGE: + { + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap ); + break; + } } } - break; } @@ -254,22 +260,29 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image Visual::BasePtr visualPtr; // first resolve url type to know which visual to create - UrlType::Type type = ResolveUrlType( url ); - if( UrlType::N_PATCH == type ) - { - visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url ); - } - else if( UrlType::SVG == type ) - { - visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url ); - } - else if( UrlType::GIF == type ) - { - visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), url ); - } - else // Regular image + VisualUrl visualUrl( url ); + switch( visualUrl.GetType() ) { - visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size ); + case VisualUrl::N_PATCH: + { + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl ); + break; + } + case VisualUrl::SVG: + { + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl ); + break; + } + case VisualUrl::GIF: + { + visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl ); + break; + } + case VisualUrl::REGULAR_IMAGE: + { + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size ); + break; + } } if( mDebugEnabled ) diff --git a/dali-toolkit/internal/visuals/visual-factory-resolve-url.h b/dali-toolkit/internal/visuals/visual-factory-resolve-url.h deleted file mode 100644 index 2c1c45b..0000000 --- a/dali-toolkit/internal/visuals/visual-factory-resolve-url.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H -#define DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H - -/* - * Copyright (c) 2016 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. - */ - -#include - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -namespace UrlType -{ - /** - * The type of the URL based on the string contents - */ - enum Type - { - REGULAR_IMAGE, - N_PATCH, - SVG, - GIF - }; -} - -/** - * Helper to resolve URL type from the string - * @param[in] url to check - * @return UrlType - */ -inline UrlType::Type ResolveUrlType( const std::string& url ) -{ - // if only one char in string, can only be regular image - const std::size_t count = url.size(); - if( count > 0 ) - { - // parsing from the end for better chance of early outs - enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX; - char SVG[ 4 ] = { 'g', 'v', 's', '.' }; - char GIF[ 4 ] = { 'f', 'i', 'g', '.' }; - unsigned int svgScore = 0; - unsigned int gifScore = 0; - int index = count; - while( --index >= 0 ) - { - const char currentChar = url[ index ]; - const std::size_t offsetFromEnd = count - index - 1u; - if( ( offsetFromEnd < sizeof(SVG) )&&( tolower( currentChar ) == SVG[ offsetFromEnd ] ) ) - { - // early out if SVG as can't be used in N patch for now - if( ++svgScore == sizeof(SVG) ) - { - return UrlType::SVG; - } - } - if( ( offsetFromEnd < sizeof(GIF) )&&( tolower( currentChar ) == GIF[ offsetFromEnd ] ) ) - { - // early out if GIF - if( ++gifScore == sizeof(GIF) ) - { - return UrlType::GIF; - } - } - switch( state ) - { - case SUFFIX: - { - if( '.' == currentChar ) - { - state = HASH; - } - break; - } - case HASH: - { - if( ( '#' == currentChar ) || ( '9' == currentChar ) ) - { - state = HASH_DOT; - } - else - { - // early out, not a valid N/9-patch URL - return UrlType::REGULAR_IMAGE; - } - break; - } - case HASH_DOT: - { - if( '.' == currentChar ) - { - return UrlType::N_PATCH; - } - else - { - // early out, not a valid N/9-patch URL - return UrlType::REGULAR_IMAGE; - } - break; - } - } - } - } - // if we got here it is a regular image - return UrlType::REGULAR_IMAGE; -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -#endif /* DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H */ diff --git a/dali-toolkit/internal/visuals/visual-url.cpp b/dali-toolkit/internal/visuals/visual-url.cpp new file mode 100644 index 0000000..c3c675d --- /dev/null +++ b/dali-toolkit/internal/visuals/visual-url.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2017 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 HEADERS +#include // for toupper() + +namespace Dali +{ +namespace Toolkit +{ +namespace Internal +{ + +namespace +{ + +VisualUrl::Location ResolveLocation( const std::string& url) +{ + const char FTP[] = { 'f', 't', 'p', ':', '/', '/' }; + const char SSH[] = { 's', 's', 'h', ':', '/', '/' }; + const char HTTP[] = { 'h', 't', 't', 'p', ':', '/', '/' }; + const char HTTPS[] = { 'h', 't', 't', 'p', 's', ':', '/', '/' }; + + const int MATCH_FTP = 0x01; + const int MATCH_SSH = 0x02; + const int MATCH_HTTP = 0x04; + const int MATCH_HTTPS = 0x08; + + const char* urlCStr = url.c_str(); + if( url.size() > 6 ) + { + if( urlCStr[3] == ':' || urlCStr[4] == ':' || urlCStr[5] == ':' ) + { + int flags = 0x0F; + for( unsigned int i=0; i < sizeof(HTTPS); ++i ) + { + char c = tolower( urlCStr[i] ); + if( i < sizeof(FTP) && (flags & MATCH_FTP) && c != FTP[i] ) + { + flags &= ~MATCH_FTP; + } + if( i < sizeof(SSH) && (flags & MATCH_SSH) && c != SSH[i] ) + { + flags &= ~MATCH_SSH; + } + if( i < sizeof(HTTP) && (flags & MATCH_HTTP) && c != HTTP[i] ) + { + flags &= ~MATCH_HTTP; + } + if( i < sizeof(HTTPS) && (flags & MATCH_HTTPS) && c != HTTPS[i] ) + { + flags &= ~MATCH_HTTPS; + } + + if( (flags & (MATCH_FTP | MATCH_SSH | MATCH_HTTP | MATCH_HTTPS )) == 0 ) + { + break; + } + } + + if( flags ) + { + return VisualUrl::REMOTE; + } + } + } + return VisualUrl::LOCAL; +} + + +VisualUrl::Type ResolveType( const std::string& url ) +{ + // if only one char in string, can only be regular image + const std::size_t count = url.size(); + if( count > 0 ) + { + // parsing from the end for better chance of early outs + enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX; + char SVG[ 4 ] = { 'g', 'v', 's', '.' }; + char GIF[ 4 ] = { 'f', 'i', 'g', '.' }; + unsigned int svgScore = 0; + unsigned int gifScore = 0; + int index = count; + while( --index >= 0 ) + { + const char currentChar = url[ index ]; + const std::size_t offsetFromEnd = count - index - 1u; + if( ( offsetFromEnd < sizeof(SVG) )&&( tolower( currentChar ) == SVG[ offsetFromEnd ] ) ) + { + // early out if SVG as can't be used in N patch for now + if( ++svgScore == sizeof(SVG) ) + { + return VisualUrl::SVG; + } + } + if( ( offsetFromEnd < sizeof(GIF) )&&( tolower( currentChar ) == GIF[ offsetFromEnd ] ) ) + { + // early out if GIF + if( ++gifScore == sizeof(GIF) ) + { + return VisualUrl::GIF; + } + } + switch( state ) + { + case SUFFIX: + { + if( '.' == currentChar ) + { + state = HASH; + } + break; + } + case HASH: + { + if( ( '#' == currentChar ) || ( '9' == currentChar ) ) + { + state = HASH_DOT; + } + else + { + // early out, not a valid N/9-patch URL + return VisualUrl::REGULAR_IMAGE; + } + break; + } + case HASH_DOT: + { + if( '.' == currentChar ) + { + return VisualUrl::N_PATCH; + } + else + { + // early out, not a valid N/9-patch URL + return VisualUrl::REGULAR_IMAGE; + } + break; + } + } + } + } + // if we got here it is a regular image + return VisualUrl::REGULAR_IMAGE; +} + +} + + +VisualUrl::VisualUrl() +: mUrl(), + mType( VisualUrl::REGULAR_IMAGE ), + mLocation( VisualUrl::LOCAL ) +{ +} + +VisualUrl::VisualUrl( const std::string& url ) +: mUrl( url ), + mType( VisualUrl::REGULAR_IMAGE ), + mLocation( VisualUrl::LOCAL ) +{ + if( ! url.empty() ) + { + mLocation = ResolveLocation( url ); + mType = ResolveType( url ); + } +} + +VisualUrl::VisualUrl( const VisualUrl& url ) +: mUrl( url.mUrl ), + mType( url.mType ), + mLocation( url.mLocation ) +{ +} + +VisualUrl& VisualUrl::operator=( const VisualUrl& url ) +{ + if( &url != this ) + { + mUrl = url.mUrl; + mType = url.mType; + mLocation = url.mLocation; + } + return *this; +} + +const std::string& VisualUrl::GetUrl() const +{ + return mUrl; +} + +VisualUrl::Type VisualUrl::GetType() const +{ + return mType; +} + +VisualUrl::Location VisualUrl::GetLocation() const +{ + return mLocation; +} + +bool VisualUrl::IsValid() const +{ + return mUrl.size() > 0u; +} + +bool VisualUrl::IsLocal() const +{ + return mLocation == VisualUrl::LOCAL; +} + + + +} // Internal +} // Toolkit +} // Dali diff --git a/dali-toolkit/internal/visuals/visual-url.h b/dali-toolkit/internal/visuals/visual-url.h new file mode 100644 index 0000000..d9ed48a --- /dev/null +++ b/dali-toolkit/internal/visuals/visual-url.h @@ -0,0 +1,119 @@ +#ifndef DALI_TOOLKIT_INTERNAL_VISUAL_URL_H +#define DALI_TOOLKIT_INTERNAL_VISUAL_URL_H + +/* + * Copyright (c) 2017 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. + */ + +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +class VisualUrl +{ +public: + + /** + * The type of the URL based on the string contents + */ + enum Type + { + REGULAR_IMAGE, + N_PATCH, + SVG, + GIF + }; + + enum Location + { + LOCAL, + REMOTE + }; + + /** + * Default Constructor. + * Resulting URL is not valid + */ + VisualUrl(); + + /** + * Constructor. + * Determines type of visual and whether the url is local or remote + * @param[in] url The URL to store and resolve + */ + VisualUrl( const std::string& url ); + + /** + * Copy constructor + * @param[in] url The VisualUrl to copy + */ + VisualUrl( const VisualUrl& url ); + + /** + * Assignment operator + * @param[in] url The VisualUrl to copy + */ + VisualUrl& operator=( const VisualUrl& url ); + + /** + * Get the full URL + * @return The url + */ + const std::string& GetUrl() const; + + /** + * Get the visual type of the URL + * @return The visual type of the URL + */ + Type GetType() const; + + /** + * Is the URL is local to the device, or remote? + * @return the location of the resource + */ + Location GetLocation() const; + + /** + * Is the URL valid? + * @return true if the URL has length + */ + bool IsValid() const; + + /** + * @return true if the location is LOCAL + */ + bool IsLocal() const; + +private: + std::string mUrl; + Type mType; + Location mLocation; +}; + + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali + +#endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */