Merge "Implement scroll bar in the TextEditor" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 15 Mar 2017 14:35:27 +0000 (07:35 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Wed, 15 Mar 2017 14:35:27 +0000 (07:35 -0700)
1  2 
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/internal/text/text-controller.cpp

@@@ -87,6 -87,9 +87,9 @@@ const char* const PROPERTY_NAME_INPUT_O
  
  const char* const PROPERTY_NAME_SMOOTH_SCROLL                        = "smoothScroll";
  const char* const PROPERTY_NAME_SMOOTH_SCROLL_DURATION               = "smoothScrollDuration";
+ const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR                    = "enableScrollBar";
+ const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION             = "scrollBarShowDuration";
+ const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION             = "scrollBarFadeDuration";
  
  const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
  
@@@ -102,10 -105,6 +105,10 @@@ const float SCROLL_SPEED = 300.f
  const unsigned int DEFAULT_FONT_SIZE = 1152u;
  const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
  
 +const int KEY_A_CODE = 38;
 +const int KEY_D_CODE = 40;
 +const int KEY_WHITE_SPACE_CODE = 65;
 +
  static bool gTextChangedCallBackCalled;
  static bool gInputStyleChangedCallbackCalled;
  static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
@@@ -334,6 -333,9 +337,9 @@@ int UtcDaliTextEditorGetPropertyP(void
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
+   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
+   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
+   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
  
    END_TEST;
  }
@@@ -612,6 -614,16 +618,16 @@@ int UtcDaliTextEditorSetPropertyP(void
    editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
    DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
  
+   // Check the scroll bar property
+   DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), false, TEST_LOCATION );
+   editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
+   DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
+   editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
+   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+   editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
+   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
    END_TEST;
  }
  
@@@ -671,7 -683,7 +687,7 @@@ int utcDaliTextEditorTextChangedP(void
    editor.SetKeyInputFocus();
  
    gTextChangedCallBackCalled = false;
 -  application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
    DALI_TEST_CHECK( gTextChangedCallBackCalled );
  
    END_TEST;
@@@ -1073,7 -1085,7 +1089,7 @@@ int utcDaliTextEditorInputStyleChanged0
    editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
    editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
  
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
@@@ -1181,7 -1193,7 +1197,7 @@@ int utcDaliTextEditorEvent01(void
    application.Render();
  
    // Add a key event but as the text editor has not the focus it should do nothing.
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
    application.Render();
  
    // Now the text editor has the focus, so it can handle the key events.
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
    application.Render();
  
    // The second text editor has the focus. It should handle the key events.
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
@@@ -1287,8 -1299,8 +1303,8 @@@ int utcDaliTextEditorEvent02(void
    DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
  
    // Now the text editor has the focus, so it can handle the key events.
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 -  application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
@@@ -1502,7 -1514,7 +1518,7 @@@ int utcDaliTextEditorEvent04(void
    }
  
    // Add a character
 -  application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
    }
  
    // Add a character
 -  application.ProcessEvent( GenerateKey( " ", " ", 0, 0, 0, Integration::KeyEvent::Down ) );
 +  application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
    // Render and notify
    application.SendNotification();
@@@ -1559,6 -1571,9 +1575,9 @@@ int utcDaliTextEditorEvent05(void
    editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
    editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
    editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
+   editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
+   editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
+   editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
  
    // Avoid a crash when core load gl resources.
    application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
    for( unsigned int index = 0u; index < 10u; ++index )
    {
      // Add a character
 -    application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
 +    application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
  
      // Render and notify
      application.SendNotification();
    }
    DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
    DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
+   DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
+   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
+   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
  
    // Press Escape to increase coverage
    application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
@@@ -1498,6 -1498,18 +1498,18 @@@ float Controller::GetScrollAmountByUser
    return scrollAmount;
  }
  
+ bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
+ {
+   const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
+   bool isScrolled;
+   controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
+   layoutHeight = layout.height;
+   scrollPosition = mImpl->mModel->mScrollPosition.y;
+   isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
+   return isScrolled;
+ }
  // public : Relayout.
  
  Controller::UpdateTextType Controller::Relayout( const Size& size )
@@@ -1707,15 -1719,8 +1719,15 @@@ bool Controller::KeyEvent( const Dali::
      int keyCode = keyEvent.keyCode;
      const std::string& keyString = keyEvent.keyPressed;
  
 +    const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
 +
      // Pre-process to separate modifying events from non-modifying input events.
 -    if( Dali::DALI_KEY_ESCAPE == keyCode )
 +    if( isNullKey )
 +    {
 +      // In some platforms arrive key events with no key code.
 +      // Do nothing.
 +    }
 +    else if( Dali::DALI_KEY_ESCAPE == keyCode )
      {
        // Escape key is a special case which causes focus loss
        KeyboardFocusLostEvent();
  
      if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
           ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
 +         ( !isNullKey ) &&
           ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) )
      {
        // Should not change the state if the key is the shift send by the imf manager.