{
}
-void WebEngine::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > cb )
-{
-}
-
-void WebEngine::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
+void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler )
{
}
fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
+ // Create a TextVisual with a font size of 12 first
propertyMap.Clear();
propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::TEXT );
propertyMap.Insert( TextVisual::Property::ENABLE_MARKUP, true );
- propertyMap.Insert( TextVisual::Property::TEXT, "<font family='TizenSansRegular' size='12'>Hello world</font>" );
+ propertyMap.Insert( TextVisual::Property::TEXT, "<font family='TizenSans' size='12'>Hello world</font>" );
propertyMap.Insert( TextVisual::Property::MULTI_LINE, true );
- Visual::Base textVisual = factory.CreateVisual( propertyMap );
- textVisual.GetNaturalSize( naturalSize );
- DALI_TEST_EQUALS( naturalSize, Size( 86.f, 20.f ), TEST_LOCATION );
+ Visual::Base smallTextVisual = factory.CreateVisual( propertyMap );
+ Vector2 smallTextVisualNaturalSize;
+ smallTextVisual.GetNaturalSize( smallTextVisualNaturalSize );
+
+ // Then create a TextVisual with a font size of 20
+ propertyMap[ TextVisual::Property::TEXT ] = "<font family='TizenSans' size='20'>Hello world</font>";
+ Visual::Base largeTextVisual = factory.CreateVisual( propertyMap );
+ Vector2 largeTextVisualNaturalSize;
+ largeTextVisual.GetNaturalSize( largeTextVisualNaturalSize );
+
+ // Compare the sizes of the two text visuals, the second one should be bigger as it has a larger point size in the markup.
+ DALI_TEST_CHECK( smallTextVisualNaturalSize.width < largeTextVisualNaturalSize.width &&
+ smallTextVisualNaturalSize.height < largeTextVisualNaturalSize.height );
- const float height = textVisual.GetHeightForWidth( 40.f );
- DALI_TEST_EQUALS( height, 57.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+ // The height returned for a particular width should also be greater for the large text visual
+ DALI_TEST_CHECK( smallTextVisual.GetHeightForWidth( 40.f ) < largeTextVisual.GetHeightForWidth( 40.f ) );
//AnimatedImageVisual
Visual::Base animatedImageVisual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
WebView view = WebView::New( "ko-KR", "Asia/Seoul" );
view.LoadHTMLString( "<body>Hello World!</body>" );
- view.AddJavaScriptInterface( "jsObject", "jsFunction",
- []( const std::string& arg ) -> std::string {
- return arg + " World!";
+ view.AddJavaScriptMessageHandler( "jsObject",
+ []( const std::string& arg ) {
}
);
- view.EvaluateJavaScript( "jsObject.jsFunction('Hello')" );
- view.RemoveJavascriptInterface( "jsObject", "jsFunction" );
+ view.EvaluateJavaScript( "jsObject.postMessage('Hello')" );
DALI_TEST_CHECK( view );
Dali::Toolkit::GetImpl( *this ).EvaluateJavaScript( script );
}
-void WebView::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > callback )
+void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler )
{
- Dali::Toolkit::GetImpl( *this ).AddJavaScriptInterface( exposedObjectName, jsFunctionName, callback );
-}
-
-void WebView::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
-{
- Dali::Toolkit::GetImpl( *this ).RemoveJavascriptInterface( exposedObjectName, jsFunctionName );
+ Dali::Toolkit::GetImpl( *this ).AddJavaScriptMessageHandler( exposedObjectName, handler );
}
void WebView::ClearHistory()
void GoBack();
/**
- * @brief Evaluates JavaScript code represented as a string.
- *
- * @param[in] script The JavaScript code
- */
+ * @brief Evaluates JavaScript code represented as a string.
+ *
+ * @param[in] script The JavaScript code
+ */
void EvaluateJavaScript( const std::string& script );
/**
- * @brief Adds a JavaScript interface.
- *
- * @param[in] exposedObjectName The name of exposed object
- * @param[in] jsFunctionName The name of JavaScript function
- * @param[in] callback The callback function
- */
- void AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > callback );
-
- /**
- * @brief Removes a JavaScript interface.
- *
- * @param[in] exposedObjectName The name of exposed object
- * @param[in] jsFunctionName The name of JavaScript function
- */
- void RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName );
+ * @brief Inject a JavaScript object with a message handler into the WebView.
+ *
+ * @note The injected object will appear in the JavaScript context to be loaded next.
+ *
+ * Example:
+ *
+ * 1. Native
+ *
+ * webview.AddJavaScriptMessageHandler( "myObject", []( const std::string& message ) {
+ * printf( "Received a message from JS: %s", message.c_str() );
+ * });
+ *
+ * // Start WebView by loading URL
+ * webview.LoadUrl( url );
+ *
+ * 2. JavaScript
+ *
+ * myObject.postMessage( "Hello World!" ); // "Received a message from JS: Hello World!"
+ *
+ *
+ * @param[in] exposedObjectName The name of exposed object
+ * @param[in] handler The callback function
+ */
+ void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
/**
* @brief Clears the history of Web.
}
}
-void WebView::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > callback )
+void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler )
{
if ( mWebEngine )
{
- mWebEngine.AddJavaScriptInterface( exposedObjectName, jsFunctionName, callback );
- }
-}
-
-void WebView::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
-{
- if ( mWebEngine )
- {
- mWebEngine.RemoveJavascriptInterface( exposedObjectName, jsFunctionName );
+ mWebEngine.AddJavaScriptMessageHandler( exposedObjectName, handler );
}
}
void EvaluateJavaScript( const std::string& script );
/**
- * @copydoc Dali::WebEngine::AddJavaScriptInterface()
+ * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
*/
- void AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > callback );
-
- /**
- * @copydoc Dali::WebEngine::RemoveJavascriptInterface()
- */
- void RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName );
+ void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
/**
* @copydoc Dali::WebEngine::ClearHistory()
const unsigned int TOOLKIT_MAJOR_VERSION = 1;
const unsigned int TOOLKIT_MINOR_VERSION = 4;
-const unsigned int TOOLKIT_MICRO_VERSION = 3;
+const unsigned int TOOLKIT_MICRO_VERSION = 4;
const char * const TOOLKIT_BUILD_DATE = __DATE__ " " __TIME__;
#ifdef DEBUG_ENABLED
Name: dali-toolkit
Summary: Dali 3D engine Toolkit
-Version: 1.4.3
+Version: 1.4.4
Release: 1
Group: System/Libraries
License: Apache-2.0 and BSD-3-Clause and MIT